插入 postgres DB - 印地语

Insert in postgres DB - Hindi

我正在创建一个 Java 应用程序,我想在其中输入非英语语言的数据。例如。我想用印地语 (UTF-8) 字符输入数据。我已将数据转换为十六进制字符串 '\xe0\xa4\xa8\xe0\xa4\xbe\xe0\xa4\x97\xe0\xa4\xb0\xe0\xa4\xbf\xe0\xa4\x95'

但是,当我尝试使用 convert_from 将数据转换回印地语时,出现以下错误:

select convert_from('\xe0\xa4\xa8\xe0\xa4\xbe\xe0\xa4\x97\xe0\xa4\xb0\xe0\xa4\xbf\xe0\xa4\x95', 'UTF8') aa

错误:

ERROR:  invalid hexadecimal digit: "\"
LINE 1: select convert_from('\xe0\xa4\xa8\xe0\xa4\xbe\xe0\xa4\x97\xe...
                            ^
********** Error **********

ERROR: invalid hexadecimal digit: "\"
SQL state: 22023
Character: 21

我正在使用 Postgres。

您有多种选择。如果你的数据库已经是 UTF8(并且客户端编码也是 UTF8),只需使用 Escape literals:

select E'\xe0\xa4\xa8\xe0\xa4\xbe\xe0\xa4\x97\xe0\xa4\xb0\xe0\xa4\xbf\xe0\xa4\x95'

当您的数据库不是 UTF8(但您​​的客户端编码是 UTF8)时使用 convert_from() 和转义文字:

select convert_from(E'\xe0\xa4\xa8\xe0\xa4\xbe\xe0\xa4\x97\xe0\xa4\xb0\xe0\xa4\xbf\xe0\xa4\x95', 'UTF8')

当您的数据库和客户端编码都不是 UTF8 时,将 convert_from()decode() 与简单文字一起使用:

convert_from(decode('e0a4a8e0a4bee0a497e0a4b0e0a4bfe0a495', 'hex'), 'UTF8')

http://rextester.com/SPGFDP50612

我已将数据转换为十六进制字符串 -- 无论如何,当您使用准备好的语句并将原始数据绑定为它的参数时,这些问题不应该出现。您的语言的绑定应该处理转换,而不是您。

  1. yum 在 centos7

    上安装 hindi
  2. 安装 postgres 9 或 10 任何版本

  3. 创建 table aayurved( utpaad char(41),sankhya char(5),mishran1 char(40),mishran2 char(41));

  4. insert into aayurved values('database',0,'locking','session');