convert_to() 是一个系统函数,用于将数据库编码的文本字符串转换为指定编码的 bytea 字符串。
convert_to() 在 PostgreSQL 8.3 中添加。
用法
convert_to (stringtext,dest_encodingname) →bytea
如果目标编码与数据库编码不兼容,或者提供的字符串包含目标编码的无效字节序列,则会引发 ERROR。
变更历史
- PostgreSQL 8.3
- 添加于 (commit 55613bf9)
示例
convert_to() 的基本用法示例
postgres=# SELECT convert_to('ä', 'LATIN1');
convert_to
------------
\xe4
(1 row)
尝试执行一次转换,其中提供的字符串包含指定目标编码的无效字节序列
postgres=# SELECT convert_to('ä', 'SJIS');
ERROR: character with byte sequence 0xc3 0xa4 in encoding "UTF8" has no equivalent in encoding "SJIS"
参考资料
- PostgreSQL 文档: 文本/二进制字符串转换函数
