Postgresql 二进制字符串函数和操作符

1、SQL 二进制字符串函数和操作符

函数返回类型描述例子结果
string || string bytea 字符串连接 E'\\\\Post'::bytea || E'\\047gres\\000'::bytea \\Post'gres\000
get_bit(stringoffset) int 从字符串中抽取位 get_bit(E'Th\\000omas'::bytea, 45) 1
get_byte(stringoffset) int 从字符串中抽取字节 get_byte(E'Th\\000omas'::bytea, 4) 109
octet_length(string) int 二进制字符串中的字节数 octet_length( E'jo\\000se'::bytea) 5
position(substring in string) int 特定子字符串的位置 position(E'\\000om'::bytea in E'Th\\000omas'::bytea) 3
set_bit(stringoffsetnewvalue) bytea 设置字符串中的位 set_bit(E'Th\\000omas'::bytea, 45, 0) Th\000omAs
set_byte(stringoffsetnewvalue) bytea 设置字符串中的字节 set_byte(E'Th\\000omas'::bytea, 4, 64) Th\000o@as
substring(string [from int] [for int]) bytea 抽取子字符串 substring(E'Th\\000omas'::bytea from 2 for 3) h\000o
trim([both] bytes from string) bytea 从 string 的开头和结尾删除只包含 bytes 中字节的最长字符串 trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) Tom

2、其它二进制字符串函数

函数返回类型描述例子结果
btrim(string byteabytes bytea) bytea 从 string 的开头和结尾删除只包含 bytes 中字节的最长的字符串 btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea) trim
decode(string texttype text) bytea 把之前用 encode 编码的结果 string 解码为二进制字符串。参数类型和 encode 相同。 decode(E'123\\000456', 'escape') 123\000456
encode(string byteatype text) text 把二进制字符串编码为只包含 ASCII 的表现形式。支持:base64hexescape encode(E'123\\000456'::bytea, 'escape') 123\000456
length(string) int 二进制字符串的长度 length(E'jo\\000se'::bytea) 5
md5(string) text 计算 string 的MD5散列值,以十六进制方式返回结果。 md5(E'Th\\000omas'::bytea) 8ab2d3c9689aaf18 b4958c334c82d8b1
posted @ 2021-12-03 13:48  数据库集中营  阅读(521)  评论(0编辑  收藏  举报