diff --git a/doc/src/sgml/func/func-binarystring.sgml b/doc/src/sgml/func/func-binarystring.sgml
index dd7037811afe..98f12c05bfa9 100644
--- a/doc/src/sgml/func/func-binarystring.sgml
+++ b/doc/src/sgml/func/func-binarystring.sgml
@@ -200,11 +200,11 @@
substring
- substring ( bytes bytea FROM start integer FOR count integer )
+ substring ( source bytea FROM start integer FOR count integer )
bytea
- Extracts the substring of bytes starting at
+ Extracts the substring of source 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
@@ -216,6 +216,26 @@
+
+
+
+ substring
+
+ substring ( source bytea, start integer , count integer )
+ bytea
+
+
+ Extracts the substring of source starting at
+ the start'th byte,
+ and stopping after count bytes if that is
+ specified.
+
+
+ substring(source=>'\x1234567890'::bytea, start=>3, count=>2)
+ \x5678
+
+
+
@@ -571,15 +591,15 @@
substr
- substr ( bytes bytea, start integer , count integer )
+ substr ( source bytea, start integer , count integer )
bytea
- Extracts the substring of bytes starting at
+ Extracts the substring of source starting at
the start'th byte,
and extending for count bytes if that is
specified. (Same
- as substring(bytes
+ as substring(source
from start
for count).)
diff --git a/doc/src/sgml/func/func-bitstring.sgml b/doc/src/sgml/func/func-bitstring.sgml
index f03dd63afcc6..9f5dcb6ff2aa 100644
--- a/doc/src/sgml/func/func-bitstring.sgml
+++ b/doc/src/sgml/func/func-bitstring.sgml
@@ -279,11 +279,31 @@
substring
- substring ( bits bit FROM start integer FOR count integer )
+ substring ( source bit, start integer , count integer )
bit
- Extracts the substring of bits starting at
+ Extracts the substring of source starting at
+ the start'th bit,
+ and stopping after count bits if that is
+ specified.
+
+
+ substring(source=>B'110010111111', start=>3, count=>2)
+ 00
+
+
+
+
+
+
+ substring
+
+ substring ( source bit FROM start integer FOR count integer )
+ bit
+
+
+ Extracts the substring of source 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
diff --git a/doc/src/sgml/func/func-matching.sgml b/doc/src/sgml/func/func-matching.sgml
index ebe0b22c8f60..ea4c2546f855 100644
--- a/doc/src/sgml/func/func-matching.sgml
+++ b/doc/src/sgml/func/func-matching.sgml
@@ -234,13 +234,13 @@
-string SIMILAR TO pattern ESCAPE escape-character
-string NOT SIMILAR TO pattern ESCAPE escape-character
+source SIMILAR TO pattern ESCAPE escape-character
+source NOT SIMILAR TO pattern ESCAPE escape-character
The SIMILAR TO operator returns true or
- false depending on whether its pattern matches the given string.
+ false depending on whether its pattern matches the given string (the source).
It is similar to LIKE, except that it
interprets the pattern using the SQL standard's definition of a
regular expression. SQL regular expressions are a curious cross
@@ -369,15 +369,15 @@
regular expression pattern. The function can be written according
to standard SQL syntax:
-substring(string similar pattern escape escape-character)
+substring(source similar pattern escape escape-character)
or using the now obsolete SQL:1999 syntax:
-substring(string from pattern for escape-character)
+substring(source from pattern for escape-character)
or as a plain three-argument function:
-substring(string, pattern, escape-character)
+substring(source, pattern, escape)
As with SIMILAR TO, the
specified pattern must match the entire data string, or else the
@@ -581,11 +581,17 @@ substring('foobar' similar '#"o_b#"%' escape '#') NULL
- The substring function with two parameters,
- substring(string from
- pattern), provides extraction of a
- substring
- that matches a POSIX regular expression pattern. It returns null if
+ The substring function with two parameters provides extraction of a
+ substring that matches a POSIX regular expression pattern.
+ The function can be written according to standard SQL syntax:
+
+substring(source FROM pattern)
+
+ It can also written as a plain two-argument function:
+
+substring(source, pattern)
+
+ It returns null if
there is no match, otherwise the first portion of the text that matched the
pattern. But if the pattern contains any parentheses, the portion
of the text that matched the first parenthesized subexpression (the
@@ -600,8 +606,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') NULL
Some examples:
-substring('foobar' from 'o.b') oob
-substring('foobar' from 'o(.)b') o
+substring(source=>'foobar', pattern=>'o.b') oob
+substring('foobar' from 'o(.)b') o
diff --git a/doc/src/sgml/func/func-string.sgml b/doc/src/sgml/func/func-string.sgml
index 01cc94c234e6..39872181b15f 100644
--- a/doc/src/sgml/func/func-string.sgml
+++ b/doc/src/sgml/func/func-string.sgml
@@ -400,11 +400,11 @@
substring
- substring ( string text FROM start integer FOR count integer )
+ substring ( source text FROM start integer FOR count integer )
text
- Extracts the substring of string starting at
+ Extracts the substring of source 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
@@ -426,7 +426,7 @@
- substring ( string text FROM pattern text )
+ substring ( source text FROM pattern text )
text
@@ -441,11 +441,11 @@
- substring ( string text SIMILAR pattern text ESCAPE escape text )
+ substring ( source text SIMILAR pattern text ESCAPE escape text )
text
- substring ( string text FROM pattern text FOR escape text )
+ substring ( source text FROM pattern text FOR escape text )
text
@@ -1390,15 +1390,15 @@
substr
- substr ( string text, start integer , count integer )
+ substr ( source text, start integer , count integer )
text
- Extracts the substring of string starting at
+ Extracts the substring of source starting at
the start'th character,
and extending for count characters if that is
specified. (Same
- as substring(string
+ as substring(source
from start
for count).)
@@ -1412,6 +1412,57 @@
+
+
+
+ substring
+
+ substring ( source text, start integer , count integer )
+ text
+
+
+ Extracts the substring of source starting at
+ the start'th character,
+ and stopping after count characters if that is
+ specified.
+
+
+ substring(source=>'Thomas', start=>2, count=>3)
+ hom
+
+
+
+
+
+ substring ( source text, pattern text, escape text)
+ text
+
+
+ Extracts the first substring matching SQL regular expression;
+ see .
+
+
+ substring('Thomas', '%#"o_a#"_', '#')
+ oma
+
+
+
+
+
+ substring ( source text, pattern text )
+ text
+
+
+ Extracts the first substring matching POSIX regular expression; see
+ .
+
+
+ substring('Thomas', '...$')
+ mas
+
+
+
+
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 2d946d6d9e9b..f0850f9ef647 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -42,7 +42,7 @@ CREATE OR REPLACE FUNCTION rpad(text, integer)
IMMUTABLE PARALLEL SAFE STRICT COST 1
RETURN rpad($1, $2, ' ');
-CREATE OR REPLACE FUNCTION "substring"(text, text, text)
+CREATE OR REPLACE FUNCTION "substring"(source text, pattern text, escape text)
RETURNS text
LANGUAGE sql
IMMUTABLE PARALLEL SAFE STRICT COST 1
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 34b7fddb0e7a..e22eaaa34ade 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -3718,6 +3718,7 @@
prosrc => 'rtrim' },
{ oid => '877', descr => 'extract portion of string',
proname => 'substr', prorettype => 'text', proargtypes => 'text int4 int4',
+ proargnames => '{source, start, count}',
prosrc => 'text_substr' },
{ oid => '878', descr => 'map a set of characters appearing in string',
proname => 'translate', prorettype => 'text', proargtypes => 'text text text',
@@ -3736,6 +3737,7 @@
prosrc => 'rtrim1' },
{ oid => '883', descr => 'extract portion of string',
proname => 'substr', prorettype => 'text', proargtypes => 'text int4',
+ proargnames => '{source, start}',
prosrc => 'text_substr_no_len' },
{ oid => '884', descr => 'trim selected characters from both ends of string',
proname => 'btrim', prorettype => 'text', proargtypes => 'text text',
@@ -3746,9 +3748,11 @@
{ oid => '936', descr => 'extract portion of string',
proname => 'substring', prorettype => 'text', proargtypes => 'text int4 int4',
+ proargnames => '{source, start, count}',
prosrc => 'text_substr' },
{ oid => '937', descr => 'extract portion of string',
proname => 'substring', prorettype => 'text', proargtypes => 'text int4',
+ proargnames => '{source, start}',
prosrc => 'text_substr_no_len' },
{ oid => '2087',
descr => 'replace all occurrences in string of old_substr with new_substr',
@@ -4166,6 +4170,7 @@
prosrc => 'bitcat' },
{ oid => '1680', descr => 'extract portion of bitstring',
proname => 'substring', prorettype => 'bit', proargtypes => 'bit int4 int4',
+ proargnames => '{source, start, count}',
prosrc => 'bitsubstr' },
{ oid => '1681', descr => 'bitstring length',
proname => 'length', prorettype => 'int4', proargtypes => 'bit',
@@ -4195,6 +4200,7 @@
prosrc => 'bitposition' },
{ oid => '1699', descr => 'extract portion of bitstring',
proname => 'substring', prorettype => 'bit', proargtypes => 'bit int4',
+ proargnames => '{source, start}',
prosrc => 'bitsubstr_no_len' },
{ oid => '3030', descr => 'substitute portion of bitstring',
@@ -6300,15 +6306,19 @@
prosrc => 'byteacat' },
{ oid => '2012', descr => 'extract portion of string',
proname => 'substring', prorettype => 'bytea',
+ proargnames => '{source, start, count}',
proargtypes => 'bytea int4 int4', prosrc => 'bytea_substr' },
{ oid => '2013', descr => 'extract portion of string',
proname => 'substring', prorettype => 'bytea', proargtypes => 'bytea int4',
+ proargnames => '{source, start}',
prosrc => 'bytea_substr_no_len' },
{ oid => '2085', descr => 'extract portion of string',
proname => 'substr', prorettype => 'bytea', proargtypes => 'bytea int4 int4',
+ proargnames => '{source, start, count}',
prosrc => 'bytea_substr' },
{ oid => '2086', descr => 'extract portion of string',
proname => 'substr', prorettype => 'bytea', proargtypes => 'bytea int4',
+ proargnames => '{source, start}',
prosrc => 'bytea_substr_no_len' },
{ oid => '2014', descr => 'position of substring',
proname => 'position', prorettype => 'int4', proargtypes => 'bytea bytea',
@@ -6500,9 +6510,11 @@
{ oid => '2073', descr => 'extract text matching regular expression',
proname => 'substring', prorettype => 'text', proargtypes => 'text text',
+ proargnames => '{source, pattern}',
prosrc => 'textregexsubstr' },
{ oid => '2074', descr => 'extract text matching SQL regular expression',
proname => 'substring', prolang => 'sql', prorettype => 'text',
+ proargnames => '{source, pattern, escape}',
proargtypes => 'text text text', prosrc => 'see system_functions.sql' },
{ oid => '2075', descr => 'convert int8 to bitstring',