git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 68de144)
Clean up grammar a bit
2020年6月29日 08:36:52 +0000 (10:36 +0200)
2020年6月29日 09:05:00 +0000 (11:05 +0200)
Simplify the grammar specification of substring() and overlay() a bit,
simplify and update some comments.

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


diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e669d75a5af36550ac20609fd993f8af3d02e4f3..1a843049f05517b2015b282bddca573daf9b394d 100644 (file)
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -452,7 +452,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%type <list> extract_list overlay_list position_list
%type <list> substr_list trim_list
%type <list> opt_interval interval_second
-%type <node> overlay_placing substr_from substr_for
%type <str> unicode_normal_form
%type <boolean> opt_instead
@@ -13797,11 +13796,6 @@ func_expr_common_subexpr:
}
| 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);
}
| POSITION '(' position_list ')'
@@ -14437,63 +14431,45 @@ unicode_normal_form:
| NFKD { $$ = "nfkd"; }
;
-/* 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() arguments */
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:
b_expr IN_P b_expr { $$ = list_make2(3,ドル 1ドル); }
| /*EMPTY*/ { $$ = NIL; }
;
-/* 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日
- */
+/* SUBSTRING() arguments */
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 */
- $$ = list_make3(1,ドル $3, 2ドル);
+ /* not legal per SQL, but might as well allow it */
+ $$ = 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
* a textual FOR value, we forcibly cast the argument
@@ -14504,9 +14480,13 @@ substr_list:
* is unknown or doesn't have an implicit cast to int4.
*/
$$ = list_make3(1,ドル makeIntConst(1, -1),
- makeTypeCast($2,
+ makeTypeCast($3,
SystemTypeName("int4"), -1));
}
+ /*
+ * We also want to support generic substring functions that
+ * accept the usual generic list of arguments.
+ */
| expr_list
{
$$ = 1ドル;
@@ -14515,13 +14495,6 @@ substr_list:
{ $$ = NIL; }
;
-substr_from:
- FROM a_expr { $$ = 2ドル; }
- ;
-
-substr_for: FOR a_expr { $$ = 2ドル; }
- ;
-
trim_list: a_expr FROM expr_list { $$ = lappend(3,ドル 1ドル); }
| FROM expr_list { $$ = 2ドル; }
| expr_list { $$ = 1ドル; }
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /