postgresql 字符集

前端之家收集整理的这篇文章主要介绍了postgresql 字符集前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

postgresql 字符集

postgresql数据库支持多种字符集,在配置字符集时要分清楚服务器与客户端的字符集,字符集不一致尽管有时能够发生转换,但带来的问题也很头疼。语言环境的配置也很重要。
服务器字符集<来自文档>:

代码
  1. Name Description Language Server? Bytes/Char Aliases
  2. BIG5 Big Five Traditional Chinese No 1-2 WIN950,Windows950
  3. EUC_CN Extended UNIX Code-CN Simplified Chinese Yes 3
  4. EUC_JP Extended UNIX CodeJP Japanese Yes
  5. EUC_JIS_2004 Extended UNIX CodeJP,JIS X 0213 Japanese Yes
  6. EUC_KR Extended UNIX CodeKR Korean Yes
  7. EUC_TW Extended UNIX CodeTW Traditional Chinese,Taiwanese Yes
  8. GB18030 National Standard Chinese No
  9. GBK Extended National Standard Simplified Chinese No WIN936,Windows936
  10. ISO_8859_5 ISO 88595,ECMA 113 LatinCyrillic Yes
  11. ISO_8859_6 ISO 6114Arabic Yes
  12. ISO_8859_7 ISO 7118Greek Yes
  13. ISO_8859_8 ISO 8121Hebrew Yes
  14. JOHAB JOHAB Korean (Hangul) No
  15. KOI8 KOI8R(U) Cyrillic Yes KOI8R
  16. LATIN1 ISO 94 Western European Yes ISO88591
  17. LATIN2 ISO Central European Yes ISO88592
  18. LATIN3 ISO South European Yes ISO88593
  19. LATIN4 ISO 4 North European Yes ISO88594
  20. LATIN5 ISO 9128 Turkish Yes ISO88599
  21. LATIN6 ISO 10144 Nordic Yes ISO885910
  22. LATIN7 ISO 13 Baltic Yes ISO885913
  23. LATIN8 ISO 14 Celtic Yes ISO885914
  24. LATIN9 ISO 15 LATIN1 with Euro and accents Yes ISO885915
  25. LATIN10 ISO 1614111 Romanian Yes ISO885916
  26. MULE_INTERNAL Mule internal code Multilingual Emacs Yes
  27. SJIS Shift JIS Japanese No Mskanji,ShiftJIS,WIN932,Windows932
  28. SHIFT_JIS_2004 Shift JIS,0)"> Japanese No
  29. sql_ASCII unspecified (see text) any Yes
  30. UHC Unified Hangul Code Korean No WIN949,Windows949
  31. UTF8 Unicode,bit all Yes Unicode
  32. WIN866 Windows CP866 Cyrillic Yes ALT
  33. WIN874 Windows CP874 Thai Yes
  34. WIN1250 Windows CP1250 Central European Yes
  35. WIN1251 Windows CP1251 Cyrillic Yes WIN
  36. WIN1252 Windows CP1252 Western European Yes
  37. WIN1253 Windows CP1253 Greek Yes
  38. WIN1254 Windows CP1254 Turkish Yes
  39. WIN1255 Windows CP1255 Hebrew Yes
  40. WIN1256 Windows CP1256 Arabic Yes
  41. WIN1257 Windows CP1257 Baltic Yes
  42. WIN1258 Windows CP1258 Vietnamese Yes ABC,TCVN,TCVN5712,VSCII

常用的简体中文字符集是UTF8和EUC_CN两种。
自动转换字符集<来自文档>:

代码

以下针对客户端与服务器字符集配置问题作几个小测试。

测试一:服务器、客户端、语言环境一致的情况

代码
[postgre@iss3984 ~]$ echo $LANG en_US.UTF [postgre@iss3984 ]$ psql daduxiong Welcome to psql 8.3.11 (server ),the Postgresql interactive terminal. Type: \copyright for distribution terms \h help with sql commands \ help with psql commands \g or terminate with semicolon to execute query \q to quit daduxiong=# \l List of databases Name | Owner Encoding -----------+---------+---------- daduxiong postgre UTF8 postgres UTF8 template0 UTF8 template1 UTF8 ( rows) daduxiong# show client_encoding; client_encoding ----------------- UTF8 ( row) daduxiong# insert into t1 values ('中国'); INSERT 0 daduxiong# select * from t1; id name ----+------------------------ 中国 ( row)

服务器与客户端字符集相同,在数据录入时不发生字符集转换;因语言环境也相同所以展现不会出现乱码。

测试二:客户端与服务器、语言环境不一致的情况

代码

客户端与服务器的字符集不一致,在数据录入时将发生字符集转换;当前展现的第二条记录非乱码形式是因为客户端字符集为GBK,在UTF8下同样出现乱码,在使用时需要语言环境进行配置。

测试三:服务器与客户端、语言环境不一致的情况

代码

客户端、语言环境均配置为GBK字符集,在当前环境下展现的为非乱码形式,数据录入时将发生字符集转换。

测试四:服务器与客户端、语言环境恢复一致的情况

代码 通过恢复原始的字符集状态,所有环境均为UTF8字符集,此时发现经过字符集转换后的内容为乱码。

猜你在找的Postgre SQL相关文章