mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add current substring regular expression syntax
SQL:1999 had syntax SUBSTRING(text FROM pattern FOR escapechar) but this was replaced in SQL:2003 by the more clear SUBSTRING(text SIMILAR pattern ESCAPE escapechar) but this was never implemented in PostgreSQL. This patch adds that new syntax as an alternative in the parser, and updates documentation and tests to indicate that this is the preferred alternative now. Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Vik Fearing <vik@postgresfriends.org> Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr> Discussion: https://www.postgresql.org/message-id/flat/a15db31c-d0f8-8ce0-9039-578a31758adb%402ndquadrant.com
This commit is contained in:
@ -2669,15 +2669,21 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
|
||||
|
||||
<row>
|
||||
<entry role="func_table_entry"><para role="func_signature">
|
||||
<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> )
|
||||
<returnvalue>text</returnvalue>
|
||||
</para>
|
||||
<para role="func_signature">
|
||||
<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> )
|
||||
<returnvalue>text</returnvalue>
|
||||
</para>
|
||||
<para>
|
||||
Extracts substring matching <acronym>SQL</acronym> regular expression;
|
||||
see <xref linkend="functions-similarto-regexp"/>.
|
||||
see <xref linkend="functions-similarto-regexp"/>. The first form has
|
||||
been specified since SQL:2003; the second form was only in SQL:1999
|
||||
and should be considered obsolete.
|
||||
</para>
|
||||
<para>
|
||||
<literal>substring('Thomas' from '%#"o_a#"_' for '#')</literal>
|
||||
<literal>substring('Thomas' similar '%#"o_a#"_' escape '#')</literal>
|
||||
<returnvalue>oma</returnvalue>
|
||||
</para></entry>
|
||||
</row>
|
||||
@ -5160,7 +5166,11 @@ cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation>
|
||||
The <function>substring</function> function with three parameters
|
||||
provides extraction of a substring that matches an SQL
|
||||
regular expression pattern. The function can be written according
|
||||
to SQL99 syntax:
|
||||
to standard SQL syntax:
|
||||
<synopsis>
|
||||
substring(<replaceable>string</replaceable> similar <replaceable>pattern</replaceable> escape <replaceable>escape-character</replaceable>)
|
||||
</synopsis>
|
||||
or using the now obsolete SQL:1999 syntax:
|
||||
<synopsis>
|
||||
substring(<replaceable>string</replaceable> from <replaceable>pattern</replaceable> for <replaceable>escape-character</replaceable>)
|
||||
</synopsis>
|
||||
@ -5201,8 +5211,8 @@ substring(<replaceable>string</replaceable>, <replaceable>pattern</replaceable>,
|
||||
<para>
|
||||
Some examples, with <literal>#"</literal> delimiting the return string:
|
||||
<programlisting>
|
||||
substring('foobar' from '%#"o_b#"%' for '#') <lineannotation>oob</lineannotation>
|
||||
substring('foobar' from '#"o_b#"%' for '#') <lineannotation>NULL</lineannotation>
|
||||
substring('foobar' similar '%#"o_b#"%' escape '#') <lineannotation>oob</lineannotation>
|
||||
substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</lineannotation>
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect2>
|
||||
|
Reference in New Issue
Block a user