1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +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:
Peter Eisentraut
2020-06-29 11:04:42 +02:00
parent aafefb4dcb
commit 78c887679d
8 changed files with 77 additions and 34 deletions

View File

@ -14451,7 +14451,27 @@ position_list:
| /*EMPTY*/ { $$ = NIL; }
;
/* SUBSTRING() arguments */
/*
* SUBSTRING() arguments
*
* Note that SQL:1999 has both
*
* text FROM int FOR int
*
* and
*
* text FROM pattern FOR escape
*
* In the parser we map them both to a call to the substring() function and
* rely on type resolution to pick the right one.
*
* In SQL:2003, the second variant was changed to
*
* text SIMILAR pattern ESCAPE escape
*
* We could in theory map that to a different function internally, but
* since we still support the SQL:1999 version, we don't.
*/
substr_list:
a_expr FROM a_expr FOR a_expr
{
@ -14483,6 +14503,10 @@ substr_list:
makeTypeCast($3,
SystemTypeName("int4"), -1));
}
| a_expr SIMILAR a_expr ESCAPE a_expr
{
$$ = list_make3($1, $3, $5);
}
/*
* We also want to support generic substring functions that
* accept the usual generic list of arguments.