↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2
历史版本PostgreSQL 7.3 已于 2007 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本。

6.5. 二进制串函数和操作符 #

本节描述用于检查和操作二进制串值的函数和操作符。这里的字符串指 BYTEA 类型的值。

SQL定义了一些具有特殊语法的二进制串函数,其中使用某些关键字而不是逗号来分隔参数。详情见表 6.9。其中一些函数也使用常规的函数调用语法实现(见表 6.10)。

表 6.9. SQL二进制串函数和操作符

函数 返回类型 描述 示例 结果
string || string bytea 字符串串接 '\\\\Post'::bytea || '\\047greSQL\\000'::bytea \\Post'greSQL\000
octet_length(string) integer 二进制串中的字节数 octet_length('jo\\000se'::bytea) 5
position(substring in string) integer 指定子串的位置 position('\\000om'::bytea in 'Th\\000omas'::bytea) 3
substring(string [from integer] [for integer]) bytea 提取子串 substring('Th\\000omas'::bytea from 2 for 3) h\000o
trim([both] characters from string) bytea 移除string开始端/结束端/两端仅含characters的最长字符串 trim('\\000'::bytea from '\\000Tom\\000'::bytea) Tom
get_byte(string, offset) integer 从字符串中抽取字节。 get_byte('Th\\000omas'::bytea, 4) 109
set_byte(string, offset, newvalue) bytea 在字符串中设置字节。 set_byte('Th\\000omas'::bytea, 4, 64) Th\000o@as
get_bit(string, offset) integer 从字符串中抽取位。 get_bit('Th\\000omas'::bytea, 45) 1
set_bit(string, offset, newvalue) bytea 在字符串中设置位。 set_bit('Th\\000omas'::bytea, 45, 0) Th\000omAs

还有一些其他的二进制串处理函数可用, 列于表 6.10。其中一些在内部用于实现 表 6.9中列出的 SQL 标准字符串函数。

表 6.10. 其他二进制串函数

函数 返回类型 描述 示例 结果
btrim(string bytea trim bytea) bytea 移除string开头和结尾处仅由trim中的字符组成的最长字符串。 btrim('\\000trim\\000'::bytea, '\\000'::bytea) trim
length(string) integer 二进制串的长度 length('jo\\000se'::bytea) 5
encode(string bytea, type text) text 把二进制串编码为仅含 ASCII 的表示。支持的 类型有:base64、hex、escape。 encode('123\\000456'::bytea, 'escape') 123\000456
decode(string text, type text) bytea 解码string中先前用encode()编码的二进制串。参数类型与encode()中的相同。 decode('123\\000456', 'escape') 123\000456

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。