Skip to content

Commit bd71797

Browse files
jianhe-funCommitfest Bot
authored andcommitted
add function argument name to function substring
with patch applied \df substring List of functions Schema | Name | Result data type | Argument data types | Type ------------+-----------+------------------+--------------------------------------------+------ pg_catalog | substring | bit | source bit, start integer | func pg_catalog | substring | bit | source bit, start integer, count integer | func pg_catalog | substring | bytea | source bytea, start integer | func pg_catalog | substring | bytea | source bytea, start integer, count integer | func pg_catalog | substring | text | source text, pattern text | func pg_catalog | substring | text | source text, pattern text, escape text | func pg_catalog | substring | text | source text, start integer | func pg_catalog | substring | text | source text, start integer, count integer | func (8 rows) discussion: https://postgr.es/m/CACJufxHTBkymh06D4mGKNe1YfRNFN+gFBybmygWk=PtMqu00LQ@mail.gmail.com
1 parent 2f20615 commit bd71797

File tree

6 files changed

+130
-25
lines changed

6 files changed

+130
-25
lines changed

doc/src/sgml/func/func-binarystring.sgml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@
200200
<indexterm>
201201
<primary>substring</primary>
202202
</indexterm>
203-
<function>substring</function> ( <parameter>bytes</parameter> <type>bytea</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
203+
<function>substring</function> ( <parameter>source</parameter> <type>bytea</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
204204
<returnvalue>bytea</returnvalue>
205205
</para>
206206
<para>
207-
Extracts the substring of <parameter>bytes</parameter> starting at
207+
Extracts the substring of <parameter>source</parameter> starting at
208208
the <parameter>start</parameter>'th byte if that is specified,
209209
and stopping after <parameter>count</parameter> bytes if that is
210210
specified. Provide at least one of <parameter>start</parameter>
@@ -216,6 +216,26 @@
216216
</para></entry>
217217
</row>
218218

219+
<row>
220+
<entry role="func_table_entry"><para role="func_signature">
221+
<indexterm>
222+
<primary>substring</primary>
223+
</indexterm>
224+
<function>substring</function> ( <parameter>source</parameter> <type>bytea</type>, <parameter>start</parameter> <type>integer</type> <optional>, <parameter>count</parameter> <type>integer</type> </optional> )
225+
<returnvalue>bytea</returnvalue>
226+
</para>
227+
<para>
228+
Extracts the substring of <parameter>source</parameter> starting at
229+
the <parameter>start</parameter>'th byte,
230+
and stopping after <parameter>count</parameter> bytes if that is
231+
specified.
232+
</para>
233+
<para>
234+
<literal>substring(source=>'\x1234567890'::bytea, start=>3, count=>2)</literal>
235+
<returnvalue>\x5678</returnvalue>
236+
</para></entry>
237+
</row>
238+
219239
<row>
220240
<entry role="func_table_entry"><para role="func_signature">
221241
<indexterm>
@@ -579,7 +599,7 @@
579599
the <parameter>start</parameter>'th byte,
580600
and extending for <parameter>count</parameter> bytes if that is
581601
specified. (Same
582-
as <literal>substring(<parameter>bytes</parameter>
602+
as <literal>substring(<parameter>source</parameter>
583603
from <parameter>start</parameter>
584604
for <parameter>count</parameter>)</literal>.)
585605
</para>

doc/src/sgml/func/func-bitstring.sgml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,31 @@
279279
<indexterm>
280280
<primary>substring</primary>
281281
</indexterm>
282-
<function>substring</function> ( <parameter>bits</parameter> <type>bit</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
282+
<function>substring</function> ( <parameter>source</parameter> <type>bit</type>, <parameter>start</parameter> <type>integer</type> <optional>, <parameter>count</parameter> <type>integer</type> </optional> )
283283
<returnvalue>bit</returnvalue>
284284
</para>
285285
<para>
286-
Extracts the substring of <parameter>bits</parameter> starting at
286+
Extracts the substring of <parameter>source</parameter> starting at
287+
the <parameter>start</parameter>'th bit,
288+
and stopping after <parameter>count</parameter> bits if that is
289+
specified.
290+
</para>
291+
<para>
292+
<literal>substring(source=>B'110010111111', start=>3, count=>2)</literal>
293+
<returnvalue>00</returnvalue>
294+
</para></entry>
295+
</row>
296+
297+
<row>
298+
<entry role="func_table_entry"><para role="func_signature">
299+
<indexterm>
300+
<primary>substring</primary>
301+
</indexterm>
302+
<function>substring</function> ( <parameter>source</parameter> <type>bit</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
303+
<returnvalue>bit</returnvalue>
304+
</para>
305+
<para>
306+
Extracts the substring of <parameter>source</parameter> starting at
287307
the <parameter>start</parameter>'th bit if that is specified,
288308
and stopping after <parameter>count</parameter> bits if that is
289309
specified. Provide at least one of <parameter>start</parameter>

doc/src/sgml/func/func-matching.sgml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@
234234
</indexterm>
235235

236236
<synopsis>
237-
<replaceable>string</replaceable> SIMILAR TO <replaceable>pattern</replaceable> <optional>ESCAPE <replaceable>escape-character</replaceable></optional>
238-
<replaceable>string</replaceable> NOT SIMILAR TO <replaceable>pattern</replaceable> <optional>ESCAPE <replaceable>escape-character</replaceable></optional>
237+
<replaceable>source</replaceable> SIMILAR TO <replaceable>pattern</replaceable> <optional>ESCAPE <replaceable>escape-character</replaceable></optional>
238+
<replaceable>source</replaceable> NOT SIMILAR TO <replaceable>pattern</replaceable> <optional>ESCAPE <replaceable>escape-character</replaceable></optional>
239239
</synopsis>
240240

241241
<para>
242242
The <function>SIMILAR TO</function> operator returns true or
243-
false depending on whether its pattern matches the given string.
243+
false depending on whether its pattern matches the given string (the <replaceable>source</replaceable>).
244244
It is similar to <function>LIKE</function>, except that it
245245
interprets the pattern using the SQL standard's definition of a
246246
regular expression. SQL regular expressions are a curious cross
@@ -369,15 +369,15 @@
369369
regular expression pattern. The function can be written according
370370
to standard SQL syntax:
371371
<synopsis>
372-
substring(<replaceable>string</replaceable> similar <replaceable>pattern</replaceable> escape <replaceable>escape-character</replaceable>)
372+
substring(<replaceable>source</replaceable> similar <replaceable>pattern</replaceable> escape <replaceable>escape-character</replaceable>)
373373
</synopsis>
374374
or using the now obsolete SQL:1999 syntax:
375375
<synopsis>
376-
substring(<replaceable>string</replaceable> from <replaceable>pattern</replaceable> for <replaceable>escape-character</replaceable>)
376+
substring(<replaceable>source</replaceable> from <replaceable>pattern</replaceable> for <replaceable>escape-character</replaceable>)
377377
</synopsis>
378378
or as a plain three-argument function:
379379
<synopsis>
380-
substring(<replaceable>string</replaceable>, <replaceable>pattern</replaceable>, <replaceable>escape-character</replaceable>)
380+
substring(<replaceable>source</replaceable>, <replaceable>pattern</replaceable>, <replaceable>escape</replaceable>)
381381
</synopsis>
382382
As with <literal>SIMILAR TO</literal>, the
383383
specified pattern must match the entire data string, or else the
@@ -581,11 +581,17 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
581581
</para>
582582

583583
<para>
584-
The <function>substring</function> function with two parameters,
585-
<function>substring(<replaceable>string</replaceable> from
586-
<replaceable>pattern</replaceable>)</function>, provides extraction of a
587-
substring
588-
that matches a POSIX regular expression pattern. It returns null if
584+
The <function>substring</function> function with two parameters provides extraction of a
585+
substring that matches a <acronym>POSIX</acronym> regular expression pattern.
586+
The function can be written according to standard <acronym>SQL</acronym> syntax:
587+
<synopsis>
588+
substring(<replaceable>source</replaceable> FROM <replaceable>pattern</replaceable>)
589+
</synopsis>
590+
It can also written as a plain two-argument function:
591+
<synopsis>
592+
substring(<replaceable>source</replaceable>, <replaceable>pattern</replaceable>)
593+
</synopsis>
594+
It returns null if
589595
there is no match, otherwise the first portion of the text that matched the
590596
pattern. But if the pattern contains any parentheses, the portion
591597
of the text that matched the first parenthesized subexpression (the
@@ -600,8 +606,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
600606
<para>
601607
Some examples:
602608
<programlisting>
603-
substring('foobar' from 'o.b') <lineannotation>oob</lineannotation>
604-
substring('foobar' from 'o(.)b') <lineannotation>o</lineannotation>
609+
substring(source=>'foobar', pattern=>'o.b') <lineannotation>oob</lineannotation>
610+
substring('foobar' from 'o(.)b') <lineannotation>o</lineannotation>
605611
</programlisting>
606612
</para>
607613

doc/src/sgml/func/func-string.sgml

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,11 @@
400400
<indexterm>
401401
<primary>substring</primary>
402402
</indexterm>
403-
<function>substring</function> ( <parameter>string</parameter> <type>text</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
403+
<function>substring</function> ( <parameter>source</parameter> <type>text</type> <optional> <literal>FROM</literal> <parameter>start</parameter> <type>integer</type> </optional> <optional> <literal>FOR</literal> <parameter>count</parameter> <type>integer</type> </optional> )
404404
<returnvalue>text</returnvalue>
405405
</para>
406406
<para>
407-
Extracts the substring of <parameter>string</parameter> starting at
407+
Extracts the substring of <parameter>source</parameter> starting at
408408
the <parameter>start</parameter>'th character if that is specified,
409409
and stopping after <parameter>count</parameter> characters if that is
410410
specified. Provide at least one of <parameter>start</parameter>
@@ -426,7 +426,7 @@
426426

427427
<row>
428428
<entry role="func_table_entry"><para role="func_signature">
429-
<function>substring</function> ( <parameter>string</parameter> <type>text</type> <literal>FROM</literal> <parameter>pattern</parameter> <type>text</type> )
429+
<function>substring</function> ( <parameter>source</parameter> <type>text</type> <literal>FROM</literal> <parameter>pattern</parameter> <type>text</type> )
430430
<returnvalue>text</returnvalue>
431431
</para>
432432
<para>
@@ -441,11 +441,11 @@
441441

442442
<row>
443443
<entry role="func_table_entry"><para role="func_signature">
444-
<function>substring</function> ( <parameter>string</parameter> <type>text</type> <literal>SIMILAR</literal> <parameter>pattern</parameter> <type>text</type> <literal>ESCAPE</literal> <parameter>escape</parameter> <type>text</type> )
444+
<function>substring</function> ( <parameter>source</parameter> <type>text</type> <literal>SIMILAR</literal> <parameter>pattern</parameter> <type>text</type> <literal>ESCAPE</literal> <parameter>escape</parameter> <type>text</type> )
445445
<returnvalue>text</returnvalue>
446446
</para>
447447
<para role="func_signature">
448-
<function>substring</function> ( <parameter>string</parameter> <type>text</type> <literal>FROM</literal> <parameter>pattern</parameter> <type>text</type> <literal>FOR</literal> <parameter>escape</parameter> <type>text</type> )
448+
<function>substring</function> ( <parameter>source</parameter> <type>text</type> <literal>FROM</literal> <parameter>pattern</parameter> <type>text</type> <literal>FOR</literal> <parameter>escape</parameter> <type>text</type> )
449449
<returnvalue>text</returnvalue>
450450
</para>
451451
<para>
@@ -1398,7 +1398,7 @@
13981398
the <parameter>start</parameter>'th character,
13991399
and extending for <parameter>count</parameter> characters if that is
14001400
specified. (Same
1401-
as <literal>substring(<parameter>string</parameter>
1401+
as <literal>substring(<parameter>source</parameter>
14021402
from <parameter>start</parameter>
14031403
for <parameter>count</parameter>)</literal>.)
14041404
</para>
@@ -1412,6 +1412,57 @@
14121412
</para></entry>
14131413
</row>
14141414

1415+
<row>
1416+
<entry role="func_table_entry"><para role="func_signature">
1417+
<indexterm>
1418+
<primary>substring</primary>
1419+
</indexterm>
1420+
<function>substring</function> ( <parameter>source</parameter> <type>text</type>, <parameter>start</parameter> <type>integer</type> <optional>, <parameter>count</parameter> <type>integer</type> </optional> )
1421+
<returnvalue>text</returnvalue>
1422+
</para>
1423+
<para>
1424+
Extracts the substring of <parameter>source</parameter> starting at
1425+
the <parameter>start</parameter>'th character,
1426+
and stopping after <parameter>count</parameter> characters if that is
1427+
specified.
1428+
</para>
1429+
<para>
1430+
<literal>substring(source=>'Thomas', start=>2, count=>3)</literal>
1431+
<returnvalue>hom</returnvalue>
1432+
</para></entry>
1433+
</row>
1434+
1435+
<row>
1436+
<entry role="func_table_entry"><para role="func_signature">
1437+
<function>substring</function> ( <parameter>source</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type>, <parameter>escape</parameter> <type>text</type>)
1438+
<returnvalue>text</returnvalue>
1439+
</para>
1440+
<para>
1441+
Extracts the first substring matching <acronym>SQL</acronym> regular expression;
1442+
see <xref linkend="functions-similarto-regexp"/>.
1443+
</para>
1444+
<para>
1445+
<literal>substring('Thomas', '%#"o_a#"_', '#')</literal>
1446+
<returnvalue>oma</returnvalue>
1447+
</para></entry>
1448+
</row>
1449+
1450+
<row>
1451+
<entry role="func_table_entry"><para role="func_signature">
1452+
<function>substring</function> ( <parameter>source</parameter> <type>text</type>, <parameter>pattern</parameter> <type>text</type> )
1453+
<returnvalue>text</returnvalue>
1454+
</para>
1455+
<para>
1456+
Extracts the first substring matching <acronym>POSIX</acronym> regular expression; see
1457+
<xref linkend="functions-posix-regexp"/>.
1458+
</para>
1459+
<para>
1460+
<literal>substring('Thomas', '...$')</literal>
1461+
<returnvalue>mas</returnvalue>
1462+
</para></entry>
1463+
</row>
1464+
1465+
14151466
<row>
14161467
<entry role="func_table_entry"><para role="func_signature">
14171468
<indexterm>

src/backend/catalog/system_functions.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CREATE OR REPLACE FUNCTION rpad(text, integer)
4242
IMMUTABLE PARALLEL SAFE STRICT COST 1
4343
RETURN rpad($1, $2, ' ');
4444

45-
CREATE OR REPLACE FUNCTION "substring"(text, text, text)
45+
CREATE OR REPLACE FUNCTION "substring"(source text, pattern text, escape text)
4646
RETURNS text
4747
LANGUAGE sql
4848
IMMUTABLE PARALLEL SAFE STRICT COST 1

src/include/catalog/pg_proc.dat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,9 +3748,11 @@
37483748

37493749
{ oid => '936', descr => 'extract portion of string',
37503750
proname => 'substring', prorettype => 'text', proargtypes => 'text int4 int4',
3751+
proargnames => '{source, start, count}',
37513752
prosrc => 'text_substr' },
37523753
{ oid => '937', descr => 'extract portion of string',
37533754
proname => 'substring', prorettype => 'text', proargtypes => 'text int4',
3755+
proargnames => '{source, start}',
37543756
prosrc => 'text_substr_no_len' },
37553757
{ oid => '2087',
37563758
descr => 'replace all occurrences in string of old_substr with new_substr',
@@ -4168,6 +4170,7 @@
41684170
prosrc => 'bitcat' },
41694171
{ oid => '1680', descr => 'extract portion of bitstring',
41704172
proname => 'substring', prorettype => 'bit', proargtypes => 'bit int4 int4',
4173+
proargnames => '{source, start, count}',
41714174
prosrc => 'bitsubstr' },
41724175
{ oid => '1681', descr => 'bitstring length',
41734176
proname => 'length', prorettype => 'int4', proargtypes => 'bit',
@@ -4197,6 +4200,7 @@
41974200
prosrc => 'bitposition' },
41984201
{ oid => '1699', descr => 'extract portion of bitstring',
41994202
proname => 'substring', prorettype => 'bit', proargtypes => 'bit int4',
4203+
proargnames => '{source, start}',
42004204
prosrc => 'bitsubstr_no_len' },
42014205

42024206
{ oid => '3030', descr => 'substitute portion of bitstring',
@@ -6302,9 +6306,11 @@
63026306
prosrc => 'byteacat' },
63036307
{ oid => '2012', descr => 'extract portion of string',
63046308
proname => 'substring', prorettype => 'bytea',
6309+
proargnames => '{source, start, count}',
63056310
proargtypes => 'bytea int4 int4', prosrc => 'bytea_substr' },
63066311
{ oid => '2013', descr => 'extract portion of string',
63076312
proname => 'substring', prorettype => 'bytea', proargtypes => 'bytea int4',
6313+
proargnames => '{source, start}',
63086314
prosrc => 'bytea_substr_no_len' },
63096315
{ oid => '2085', descr => 'extract portion of string',
63106316
proname => 'substr', prorettype => 'bytea', proargtypes => 'bytea int4 int4',
@@ -6504,9 +6510,11 @@
65046510

65056511
{ oid => '2073', descr => 'extract text matching regular expression',
65066512
proname => 'substring', prorettype => 'text', proargtypes => 'text text',
6513+
proargnames => '{source, pattern}',
65076514
prosrc => 'textregexsubstr' },
65086515
{ oid => '2074', descr => 'extract text matching SQL regular expression',
65096516
proname => 'substring', prolang => 'sql', prorettype => 'text',
6517+
proargnames => '{source, pattern, escape}',
65106518
proargtypes => 'text text text', prosrc => 'see system_functions.sql' },
65116519

65126520
{ oid => '2075', descr => 'convert int8 to bitstring',

0 commit comments

Comments
 (0)