convert_to()

将文本转换为指定编码的bytea字符串的函数

convert_to() 是一个系统函数,用于将数据库编码的文本字符串转换为指定编码的 bytea 字符串。

convert_to()PostgreSQL 8.3 中添加。

用法

convert_to ( string text, dest_encoding name ) → bytea

如果目标编码与数据库编码不兼容,或者提供的字符串包含目标编码的无效字节序列,则会引发 ERROR

变更历史

示例

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"

分类

bytea, 区域设置和字符集处理, 字符串操作, 系统函数

另请参阅

convert_from(), convert(), server_encoding

反馈

提交对“convert_to()”的任何评论、建议或更正,请在此处 提交