Commit aafefb4d authored by Peter Eisentraut's avatar Peter Eisentraut

Clean up grammar a bit

Simplify the grammar specification of substring() and overlay() a bit,
simplify and update some comments.
Reviewed-by: default avatarPavel Stehule <pavel.stehule@gmail.com>
Reviewed-by: default avatarVik Fearing <vik@postgresfriends.org>
Reviewed-by: default avatarFabien COELHO <coelho@cri.ensmp.fr>
Discussion: https://www.postgresql.org/message-id/flat/a15db31c-d0f8-8ce0-9039-578a31758adb%402ndquadrant.com
parent 68de1440
...@@ -452,7 +452,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); ...@@ -452,7 +452,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%type <list> extract_list overlay_list position_list %type <list> extract_list overlay_list position_list
%type <list> substr_list trim_list %type <list> substr_list trim_list
%type <list> opt_interval interval_second %type <list> opt_interval interval_second
%type <node> overlay_placing substr_from substr_for
%type <str> unicode_normal_form %type <str> unicode_normal_form
%type <boolean> opt_instead %type <boolean> opt_instead
...@@ -13797,11 +13796,6 @@ func_expr_common_subexpr: ...@@ -13797,11 +13796,6 @@ func_expr_common_subexpr:
} }
| OVERLAY '(' overlay_list ')' | OVERLAY '(' overlay_list ')'
{ {
/* overlay(A PLACING B FROM C FOR D) is converted to
* overlay(A, B, C, D)
* overlay(A PLACING B FROM C) is converted to
* overlay(A, B, C)
*/
$$ = (Node *) makeFuncCall(SystemFuncName("overlay"), $3, @1); $$ = (Node *) makeFuncCall(SystemFuncName("overlay"), $3, @1);
} }
| POSITION '(' position_list ')' | POSITION '(' position_list ')'
...@@ -14437,63 +14431,45 @@ unicode_normal_form: ...@@ -14437,63 +14431,45 @@ unicode_normal_form:
| NFKD { $$ = "nfkd"; } | NFKD { $$ = "nfkd"; }
; ;
/* OVERLAY() arguments /* OVERLAY() arguments */
* SQL99 defines the OVERLAY() function:
* o overlay(text placing text from int for int)
* o overlay(text placing text from int)
* and similarly for binary strings
*/
overlay_list: overlay_list:
a_expr overlay_placing substr_from substr_for a_expr PLACING a_expr FROM a_expr FOR a_expr
{ {
$$ = list_make4($1, $2, $3, $4); /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
$$ = list_make4($1, $3, $5, $7);
} }
| a_expr overlay_placing substr_from | a_expr PLACING a_expr FROM a_expr
{ {
$$ = list_make3($1, $2, $3); /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
$$ = list_make3($1, $3, $5);
} }
; ;
overlay_placing:
PLACING a_expr
{ $$ = $2; }
;
/* position_list uses b_expr not a_expr to avoid conflict with general IN */ /* position_list uses b_expr not a_expr to avoid conflict with general IN */
position_list: position_list:
b_expr IN_P b_expr { $$ = list_make2($3, $1); } b_expr IN_P b_expr { $$ = list_make2($3, $1); }
| /*EMPTY*/ { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; }
; ;
/* SUBSTRING() arguments /* SUBSTRING() arguments */
* SQL9x defines a specific syntax for arguments to SUBSTRING():
* o substring(text from int for int)
* o substring(text from int) get entire string from starting point "int"
* o substring(text for int) get first "int" characters of string
* o substring(text from pattern) get entire string matching pattern
* o substring(text from pattern for escape) same with specified escape char
* We also want to support generic substring functions which accept
* the usual generic list of arguments. So we will accept both styles
* here, and convert the SQL9x style to the generic list for further
* processing. - thomas 2000-11-28
*/
substr_list: substr_list:
a_expr substr_from substr_for a_expr FROM a_expr FOR a_expr
{ {
$$ = list_make3($1, $2, $3); $$ = list_make3($1, $3, $5);
} }
| a_expr substr_for substr_from | a_expr FOR a_expr FROM a_expr
{ {
/* not legal per SQL99, but might as well allow it */ /* not legal per SQL, but might as well allow it */
$$ = list_make3($1, $3, $2); $$ = list_make3($1, $5, $3);
} }
| a_expr substr_from | a_expr FROM a_expr
{ {
$$ = list_make2($1, $2); $$ = list_make2($1, $3);
} }
| a_expr substr_for | a_expr FOR a_expr
{ {
/* not legal per SQL */
/* /*
* Since there are no cases where this syntax allows * Since there are no cases where this syntax allows
* a textual FOR value, we forcibly cast the argument * a textual FOR value, we forcibly cast the argument
...@@ -14504,9 +14480,13 @@ substr_list: ...@@ -14504,9 +14480,13 @@ substr_list:
* is unknown or doesn't have an implicit cast to int4. * is unknown or doesn't have an implicit cast to int4.
*/ */
$$ = list_make3($1, makeIntConst(1, -1), $$ = list_make3($1, makeIntConst(1, -1),
makeTypeCast($2, makeTypeCast($3,
SystemTypeName("int4"), -1)); SystemTypeName("int4"), -1));
} }
/*
* We also want to support generic substring functions that
* accept the usual generic list of arguments.
*/
| expr_list | expr_list
{ {
$$ = $1; $$ = $1;
...@@ -14515,13 +14495,6 @@ substr_list: ...@@ -14515,13 +14495,6 @@ substr_list:
{ $$ = NIL; } { $$ = NIL; }
; ;
substr_from:
FROM a_expr { $$ = $2; }
;
substr_for: FOR a_expr { $$ = $2; }
;
trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); } trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
| FROM expr_list { $$ = $2; } | FROM expr_list { $$ = $2; }
| expr_list { $$ = $1; } | expr_list { $$ = $1; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment