Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaafefb4

Browse files
committed
Clean up grammar a bit
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
1 parent68de144 commitaafefb4

File tree

1 file changed

+23
-50
lines changed

1 file changed

+23
-50
lines changed

‎src/backend/parser/gram.y‎

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
452452
%type<list>extract_listoverlay_listposition_list
453453
%type<list>substr_listtrim_list
454454
%type<list>opt_intervalinterval_second
455-
%type<node>overlay_placingsubstr_fromsubstr_for
456455
%type<str>unicode_normal_form
457456

458457
%type<boolean>opt_instead
@@ -13797,11 +13796,6 @@ func_expr_common_subexpr:
1379713796
}
1379813797
|OVERLAY'('overlay_list')'
1379913798
{
13800-
/* overlay(A PLACING B FROM C FOR D) is converted to
13801-
* overlay(A, B, C, D)
13802-
* overlay(A PLACING B FROM C) is converted to
13803-
* overlay(A, B, C)
13804-
*/
1380513799
$$ = (Node *) makeFuncCall(SystemFuncName("overlay"),$3,@1);
1380613800
}
1380713801
|POSITION'('position_list')'
@@ -14437,63 +14431,45 @@ unicode_normal_form:
1443714431
|NFKD{$$ ="nfkd"; }
1443814432
;
1443914433

14440-
/* OVERLAY() arguments
14441-
* SQL99 defines the OVERLAY() function:
14442-
* o overlay(text placing text from int for int)
14443-
* o overlay(text placing text from int)
14444-
* and similarly for binary strings
14445-
*/
14434+
/* OVERLAY() arguments*/
1444614435
overlay_list:
14447-
a_exproverlay_placingsubstr_fromsubstr_for
14436+
a_exprPLACINGa_exprFROMa_exprFORa_expr
1444814437
{
14449-
$$ = list_make4($1,$2,$3,$4);
14438+
/* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D)*/
14439+
$$ = list_make4($1,$3,$5,$7);
1445014440
}
14451-
|a_exproverlay_placingsubstr_from
14441+
|a_exprPLACINGa_exprFROMa_expr
1445214442
{
14453-
$$ = list_make3($1,$2,$3);
14443+
/* overlay(A PLACING B FROM C) is converted to overlay(A, B, C)*/
14444+
$$ = list_make3($1,$3,$5);
1445414445
}
1445514446
;
1445614447

14457-
overlay_placing:
14458-
PLACINGa_expr
14459-
{$$ =$2; }
14460-
;
14461-
1446214448
/* position_list uses b_expr not a_expr to avoid conflict with general IN*/
14463-
1446414449
position_list:
1446514450
b_exprIN_Pb_expr{$$ = list_make2($3,$1); }
1446614451
|/*EMPTY*/{$$ = NIL; }
1446714452
;
1446814453

14469-
/* SUBSTRING() arguments
14470-
* SQL9x defines a specific syntax for arguments to SUBSTRING():
14471-
* o substring(text from int for int)
14472-
* o substring(text from int) get entire string from starting point "int"
14473-
* o substring(text for int) get first "int" characters of string
14474-
* o substring(text from pattern) get entire string matching pattern
14475-
* o substring(text from pattern for escape) same with specified escape char
14476-
* We also want to support generic substring functions which accept
14477-
* the usual generic list of arguments. So we will accept both styles
14478-
* here, and convert the SQL9x style to the generic list for further
14479-
* processing. - thomas 2000-11-28
14480-
*/
14454+
/* SUBSTRING() arguments*/
1448114455
substr_list:
14482-
a_exprsubstr_fromsubstr_for
14456+
a_exprFROMa_exprFORa_expr
1448314457
{
14484-
$$ = list_make3($1,$2,$3);
14458+
$$ = list_make3($1,$3,$5);
1448514459
}
14486-
|a_exprsubstr_forsubstr_from
14460+
|a_exprFORa_exprFROMa_expr
1448714461
{
14488-
/* not legal perSQL99, but might as well allow it*/
14489-
$$ = list_make3($1,$3,$2);
14462+
/* not legal perSQL, but might as well allow it*/
14463+
$$ = list_make3($1,$5,$3);
1449014464
}
14491-
|a_exprsubstr_from
14465+
|a_exprFROMa_expr
1449214466
{
14493-
$$ = list_make2($1,$2);
14467+
$$ = list_make2($1,$3);
1449414468
}
14495-
|a_exprsubstr_for
14469+
|a_exprFORa_expr
1449614470
{
14471+
/* not legal per SQL*/
14472+
1449714473
/*
1449814474
* Since there are no cases where this syntax allows
1449914475
* a textual FOR value, we forcibly cast the argument
@@ -14504,9 +14480,13 @@ substr_list:
1450414480
* is unknown or doesn't have an implicit cast to int4.
1450514481
*/
1450614482
$$ = list_make3($1, makeIntConst(1, -1),
14507-
makeTypeCast($2,
14483+
makeTypeCast($3,
1450814484
SystemTypeName("int4"), -1));
1450914485
}
14486+
/*
14487+
* We also want to support generic substring functions that
14488+
* accept the usual generic list of arguments.
14489+
*/
1451014490
| expr_list
1451114491
{
1451214492
$$ = $1;
@@ -14515,13 +14495,6 @@ substr_list:
1451514495
{ $$ = NIL; }
1451614496
;
1451714497

14518-
substr_from:
14519-
FROM a_expr{ $$ = $2; }
14520-
;
14521-
14522-
substr_for: FOR a_expr{ $$ = $2; }
14523-
;
14524-
1452514498
trim_list:a_expr FROM expr_list{ $$ =lappend($3, $1); }
1452614499
| FROM expr_list{ $$ = $2; }
1452714500
| expr_list{ $$ = $1; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp