↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Functions

substring

Extracts the substring of string starting at the start'th character if that is specified, and stopping after count characters if that is specified. Provide at least one of start and count.

English manual coverage begins with PostgreSQL 7.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

group
string
group label
字符串函数和操作符
lang
en
layout
table-new
pages
functions-string.html, functions-binarystring.html, functions-bitstring.html, functions-matching.html
prose only
false

Definition PG 18

Extracts the substring of string starting at the start'th character if that is specified, and stopping after count characters if that is specified. Provide at least one of start and count.

Signatures and overloads

substring ( string text [FROM start integer] [FOR count integer] ) → text → text
Extracts the substring of string starting at the start'th character if that is specified, and stopping after count characters if that is specified. Provide at least one of start and count.
substring ( string text FROM pattern text ) → text → text
Extracts the first substring matching POSIX regular expression; see Section 9.7.3.
substring ( string text SIMILAR pattern text ESCAPE escape text ) → text → text
Extracts the first substring matching SQL regular expression; see Section 9.7.2. The first form has been specified since SQL:2003; the second form was only in SQL:1999 and should be considered obsolete.
substring ( string text FROM pattern text FOR escape text ) → text → text
Extracts the first substring matching SQL regular expression; see Section 9.7.2. The first form has been specified since SQL:2003; the second form was only in SQL:1999 and should be considered obsolete.
substring ( bytes bytea [FROM start integer] [FOR count integer] ) → bytea → bytea
Extracts the substring of bytes starting at the start'th byte if that is specified, and stopping after count bytes if that is specified. Provide at least one of start and count.
substring ( bits bit [FROM start integer] [FOR count integer] ) → bit → bit
Extracts the substring of bits starting at the start'th bit if that is specified, and stopping after count bits if that is specified. Provide at least one of start and count.
substring(string similar pattern escape escape-character)
The substring function with three parameters provides extraction of a substring that matches an SQL regular expression pattern. The function can be written according to standard SQL syntax:
substring(string from pattern for escape-character)
The substring function with three parameters provides extraction of a substring that matches an SQL regular expression pattern. The function can be written according to standard SQL syntax:
substring(string, pattern, escape-character)
As with SIMILAR TO, the specified pattern must match the entire data string, or else the function fails and returns null. To indicate the part of the pattern for which the matching data sub-string is of interest, the pattern should contain two occurrences of the escape character followed by a double quote ("). The text matching the portion of the pattern between these separators is returned when the match is successful.

Compare versions

Complete source facts

documentation revision

{"inputs":[{"file":"functions-binarystring.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"cd434063935e362cbb3621171770936b04bafcd58673d71a20cd6992580b2d84","version":"18.7"},{"file":"functions-bitstring.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"270c5c14b6fe519e8d8cc3f7514e0202aa8d534d1e9c8f62ab1ad6802faaa531","version":"18.7"},{"file":"functions-matching.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"8cd962b980b0a1516c6ccdfd9961c2d256ad9b31e065d6c07a3ac7fcf1b69a2f","version":"18.7"},{"file":"functions-string.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"dbe9f91e55c35969d99a8d2697b6f7bd5388a24ccc2b89706a666f176025f1e2","version":"18.7"},{"file":"functions-binarystring.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"a5ee5be3c79e45371853d5c6dd8b1b3f52734bbc17726dbe626837179a1da1e0","version":"18.7"},{"file":"functions-bitstring.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"6b6423f8b2751016eae606a5cdcf7062bd62f230a0ef96b83e357418208bc67e","version":"18.7"},{"file":"functions-matching.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"eb029e71fe7fe0a8374a9956ba571b1cf112607df810495cbbccde6d51959f76","version":"18.7"},{"file":"functions-string.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"7eecd3bb343149124be0476a539f3c682476eab2a15489a0e0ad06fbb769ea9e","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:28b204fb9ed2c138153901739cd98a981867b03c8737a3d38c32e21f8867ba22

Text language: en · wiki-repair-20261023:28b204fb9ed2c138153901739cd98a981867b03c8737a3d38c32e21f8867ba22