选择 打开 改范围 完整检索页

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

文档 / 函数百科 / 字符串函数和操作符

FUNCTION字符串函数和操作符

substr

提取string从start字符开始的子字符串,并扩展count字符,如果指定了的话。

Extracts the substring of string starting at the start'th character, and extending for count characters if that is specified.

字符串函数和操作符 引入 9.0(基线) 现存至 20 devel 2 条签名 0 次签名变更

签名数
2 条
引入版本
9.0(基线)
状态
现存
签名变更
未变过
本版来源
本站译文

PostgreSQL 18 手册 · 9.4 字符串函数和操作符 官方文档

版本轨迹

相对 PostgreSQL 17 无变化。

签名

PostgreSQL 18 里 substr 的 2 条签名,按上游手册顺序排列。参数名用斜体,类型用弱化色, 之后是返回类型。说明取自本站手册译文:标「沿用」的借用了另一版的译文,标「EN」的本站暂无译文、按英文原文显示。

  1. substr ( string text, start integer [, count integer ] ) → text

    提取stringstart字符开始的子字符串,并扩展count字符,如果指定了的话。 (与 子字符串(stringstart 开始计数 count)相同。)
    • substr('alphabet', 3)phabet
    • substr('alphabet', 3, 2)ph
  2. substr ( bytes bytea, start integer [, count integer ] ) → bytea

    start字节开始提取bytes的子字符串,并扩展为count字节,如果这是指定的。 (与 substring(bytesstartcount) 相同.)
    • substr('\x1234567890'::bytea, 3, 2)\x5678

演化历史

相邻两个大版本之间的差异,新的在前。版本号链到该版的签名。

  1. PostgreSQL 13 ← 12 手册重排

    这一跳手册重排了函数表的写法,签名文本整体改写,只记函数的增删,不逐条比较签名。

签名矩阵

每条签名在给出了签名的 18 个版本里的存在情况;方格指向该版的签名。只在正文里提到此函数、没有给出签名的版本不列进来,上面的版本轨迹里仍然有它们。签名文本在 PostgreSQL 13 前后写法不同,跨越那一跳的同一条签名会显示成两行。

存在 不存在

签名 9.09.19.29.39.49.59.61011121314151617181920
substr ( string, from [, count] ) → text 存在 存在 存在 存在 存在 存在 存在 存在 存在 存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在
substr ( string text, start integer [, count integer ] ) → text 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在
substr ( bytes bytea, start integer [, count integer ] ) → bytea 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 不存在 存在 存在 存在 存在 存在 存在 存在 存在

同组函数

函数 签名 主签名 版本变动 最近变更
STRING FUNCTIONS AND OPERATORS 字符串函数和操作符 58 个
ascii基线 1 ascii ( text ) → integer
返回参数的第一个字符的数字代码。 现存
bit_length基线 3 bit_length ( text ) → integer
返回字符串中的位数(8倍于octet_length)。 现存
btrim基线 2 btrim ( string text [, characters text ] ) → text
从string的开头或结尾删除最长的只包含characters(默认是一个空格)的字符串 现存
casefold 1 casefold ( text ) → text
根据排序规则对输入字符串执行大小写折叠。 现存
char_length基线 1 char_length ( text ) → integer
返回字符串中的字符数。 现存
character_length基线 1 character_length ( text ) → integer
返回字符串中的字符数。 现存
chr基线 1 chr ( integer ) → text
返回给定代码的字符。 现存
concat 1 concat ( val1 "any" [, val2 "any" [, ...] ] ) → text
连接所有参数的文本表示。 现存
concat_ws 1 concat_ws ( sep text, val1 "any" [, val2 "any" [, ...] ] ) → text
用分隔符连接除第一个参数外的所有参数。 现存
format 2 format ( formatstr text [, formatarg "any" [, ...] ] ) → text 9.31 次
根据格式字符串对参数进行格式化;参见 Section 9.4.1。 现存
getdatabaseencoding 1 getdatabaseencoding ( ) → name
返回当前数据库的编码名称。 现存
initcap基线 1 initcap ( text ) → text
将每个单词的第一个字母转换为大写(如果该字母是双字母,且区域设置为ICU或builtin PG_UNICODE_FAST,则转换为标题大小写),其余字母转换为小写。 现存
left 1 left ( string text, n integer ) → text
以字符串返回第一个 n 字符,或在 n 为负时, 返回最后 |n| 个字符之外的全部字符。 现存
length基线 6 length ( text ) → integer 9.11 次
返回字符串中的字符数。 现存
lower基线 3 lower ( text ) → text 142 次
根据数据库的语言环境规则,将字符串转换为全部小写。 现存
lpad基线 1 lpad ( string text, length integer [, fill text ] ) → text
将string扩展为长度length,通过前置字符fill(默认空格)。 现存
ltrim基线 2 ltrim ( string text [, characters text ] ) → text 141 次
从string开始删除包含characters(默认空格)中仅包含字符的最长字符串。 现存
md5基线 2 md5 ( text ) → text
计算参数的 MD5 hash ,结果以十六进制形式写入。 现存
normalize 1 normalize ( text [, form ] ) → text
将字符串转换为指定的Unicode规范化形式。 现存
octet_length基线 4 octet_length ( text ) → integer
返回字符串的字节数。 现存
overlay基线 3 overlay ( string text PLACING newsubstring text FROM start integer [ FOR count integer ] ) → text
替换string从start字符开始的子串,并用newsubstring扩展到count字符。 现存
parse_ident 1 parse_ident ( qualified_identifier text [, strict_mode boolean DEFAULT true ] ) → text[]
将qualified_identifier拆分为一个标识符数组,删除单个标识符的任何引用。 现存
pg_client_encoding基线 1 pg_client_encoding ( ) → name
返回当前客户端编码名称。 现存
position基线 3 position ( substring text IN string text ) → integer
返回string中指定的substring的第一个起始索引,如果不存在则返回零,。 现存
quote_ident基线 1 quote_ident ( text ) → text
返回适合引用的给定字符串,作为SQL语句字符串中的标识符。 现存
quote_literal基线 2 quote_literal ( text ) → text
返回在SQL语句字符串中适当引用的给定字符串,用作字符串文字使用。 现存
quote_nullable基线 2 quote_nullable ( text ) → text
返回在SQL语句字符串中适当引用的给定字符串文字;或者,如果参数为null,则返回NULL。 现存
regexp_count 2 regexp_count ( string text, pattern text [, start integer [, flags text ] ] ) → integer 191 次
返回 POSIX 正则表达式pattern在string中匹配的次数;参见Section 9.7.3.1.2。 现存
regexp_instr 2 regexp_instr ( string text, pattern text [, start integer [, N integer [, endoption integer [, flags text [, subexpr integer ] ] ] ] ] ) → integer 191 次
返回string中第N个匹配项的POSIX正则表达式pattern出现的位置,如果没有这样的匹配项,则返回零;参见Section 9.7.3.1.3。 现存
regexp_like 2 regexp_like ( string text, pattern text [, flags text ] ) → boolean 191 次
检查 POSIX 正则表达式pattern是否在string中出现;参见Section 9.7.3.1.4。 现存
regexp_match 2 regexp_match ( string text, pattern text [, flags text ] ) → text[] 191 次
返回第一个匹配的POSIX正则表达式pattern在string中的子字符串;参见Section 9.7.3.1.5。 现存
regexp_matches基线 2 regexp_matches ( string text, pattern text [, flags text ] ) → setof text[] 191 次
返回第一个匹配的 POSIX 正则表达式pattern在string中的子字符串,或者如果使用了g标志,则返回所有匹配的子字符串; 参见Section 9.7.3.1.6。 现存
regexp_replace基线 4 regexp_replace ( string text, pattern text, replacement text [, flags text ] ) → text 193 次
替换第一个与 POSIX 正则表达式pattern匹配的子字符串,如果使用了g标志,则替换所有这样的匹配;参见Section 9.7.3.1.7。 现存
regexp_split_to_array基线 2 regexp_split_to_array ( string text, pattern text [, flags text ] ) → text[] 191 次
使用POSIX正则表达式作为分隔符拆分string,生成一个结果的数组; 参见 Section 9.7.3.1.9。 现存
regexp_split_to_table基线 2 regexp_split_to_table ( string text, pattern text [, flags text ] ) → setof text 191 次
使用POSIX正则表达式作为分隔符拆分string,生成一组结果;参见 Section 9.7.3.1.8。 现存
regexp_substr 2 regexp_substr ( string text, pattern text [, start integer [, N integer [, flags text [, subexpr integer ] ] ] ] ) → text 191 次
返回string中与第N个出现的POSIX正则表达式pattern匹配的子字符串, 如果没有这样的匹配,则返回NULL;参见Section 9.7.3.1.10。 现存
repeat基线 1 repeat ( string text, number integer ) → text
重复string指定number的次数。 现存
replace基线 1 replace ( string text, from text, to text ) → text
将string 中当前的子串from替换为子串to。 现存
reverse 2 reverse ( text ) → text 181 次
颠倒字符串中字符的顺序。 现存
right 1 right ( string text, n integer ) → text
返回字符串中的最后n个字符,或者在n>为负时,返回除了前面的|n|字符之外的所有字符。 现存
rpad基线 1 rpad ( string text, length integer [, fill text ] ) → text
扩展 string 到长度 length,通过追加fill 字符(默认为空格). 如果string 已经比 length 长,则截断它。 现存
rtrim基线 2 rtrim ( string text [, characters text ] ) → text 141 次
从string末尾删除包含characters(默认为空格)中仅包含字符的最长字符串。 现存
split_part基线 1 split_part ( string text, delimiter text, n integer ) → text
在delimiter出现时拆分string,并且返回第n个字段(从一计数),或者当n为负数时,返回|n|'th-from-last 字段。 现存
starts_with 1 starts_with ( string text, prefix text ) → boolean
如果 string 以 prefix开始就返回真。 现存
string_to_array基线 1 string_to_array ( string text, delimiter text [, null_string text ] ) → text[] 9.11 次
将string按delimiter分割,并将结果字段形成text数组。 现存
string_to_table 1 string_to_table ( string text, delimiter text [, null_string text ] ) → setof text
在出现delimiter 时拆分string,并将结果字段作为text行的集合返回。 现存
strpos基线 1 strpos ( string text, substring text ) → integer
返回在string中指定的substring的第一个起始索引,如果不存在则为零。 现存
substr基线 2 substr ( string text, start integer [, count integer ] ) → text
提取string从start字符开始的子字符串,并扩展count字符,如果指定了的话。 现存
substring基线 11 substring ( string text [ FROM start integer ] [ FOR count integer ] ) → text 193 次
如果已指定,提取string从start字符开始的子串, 并且在count字符后停止。 现存
to_ascii基线 3 to_ascii ( string text ) → text
将string从另一个编码中转换为ASCII,该编码可按名称或编号标识。 现存
to_bin 2 to_bin ( integer ) → text
将数字转换为等价的二进制补码表示。 现存
to_hex基线 2 to_hex ( integer ) → text
将数字转换为其相应的十六进制表示形式。 现存
to_oct 2 to_oct ( integer ) → text
将数字转换为等价的八进制补码表示。 现存
translate基线 1 translate ( string text, from text, to text ) → text
将string中与from集合中匹配的每个字符替换为to集合中相应的字符。 现存
trim基线 4 trim ( [ LEADING | TRAILING | BOTH ] [ characters text ] FROM string text ) → text 142 次
从string的开始、末端或两端(默认为BOTH )移除仅包含characters(默认为空格)字符的最长字符串。 现存
unicode_assigned 1 unicode_assigned ( text ) → boolean
如果字符串中的所有字符都已分配 Unicode 代码点,则返回true;否则返回false。 现存
unistr 1 unistr ( text ) → text
计算参数中的转义Unicode字符。 现存
upper基线 3 upper ( text ) → text 142 次
根据数据库的定位规则,将字符串转换为所有大写。 现存