From 78c887679d7632c1211f85eb95723f3226bf1b46 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 29 Jun 2020 11:04:42 +0200 Subject: 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 Reviewed-by: Vik Fearing Reviewed-by: Fabien COELHO Discussion: https://www.postgresql.org/message-id/flat/a15db31c-d0f8-8ce0-9039-578a31758adb%402ndquadrant.com --- doc/src/sgml/func.sgml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 7119f0b2ca5..f0658565350 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -2669,15 +2669,21 @@ repeat('Pg', 4) PgPgPgPg + substring ( string text SIMILAR pattern text ESCAPE escape text ) + text + + substring ( string text FROM pattern text FOR escape text ) text Extracts substring matching SQL regular expression; - see . + see . The first form has + been specified since SQL:2003; the second form was only in SQL:1999 + and should be considered obsolete. - substring('Thomas' from '%#"o_a#"_' for '#') + substring('Thomas' similar '%#"o_a#"_' escape '#') oma @@ -5160,7 +5166,11 @@ cast(-44 as bit(12)) 111111010100 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 SQL99 syntax: + to standard SQL syntax: + +substring(string similar pattern escape escape-character) + + or using the now obsolete SQL:1999 syntax: substring(string from pattern for escape-character) @@ -5201,8 +5211,8 @@ substring(string, pattern, Some examples, with #" delimiting the return string: -substring('foobar' from '%#"o_b#"%' for '#') oob -substring('foobar' from '#"o_b#"%' for '#') NULL +substring('foobar' similar '%#"o_b#"%' escape '#') oob +substring('foobar' similar '#"o_b#"%' escape '#') NULL -- cgit v1.2.3