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

Commit2c19928

Browse files
committed
plpgsql can assign to subscripted variables now, e.g.
x[42] := whatever;The facility is pretty primitive because it doesn't do array slicing andit has the same semantics as array update in SQL (array must alreadybe non-null, etc). But it's a start.
1 parent9e29b32 commit2c19928

File tree

4 files changed

+253
-47
lines changed

4 files changed

+253
-47
lines changed

‎src/pl/plpgsql/src/gram.y

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* procedural language
55
*
66
* IDENTIFICATION
7-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.40 2002/11/10 00:35:58 momjian Exp $
7+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.41 2003/03/25 03:16:40 tgl Exp $
88
*
99
* This software is copyrighted by Jan Wieck - Hamburg.
1010
*
@@ -105,7 +105,8 @@ staticvoid check_assignable(PLpgSQL_datum *datum);
105105
%type<nsitem>decl_aliasitem
106106
%type<str>decl_stmtsdecl_stmt
107107

108-
%type<expr>expr_until_semiexpr_until_thenexpr_until_loop
108+
%type<expr>expr_until_semiexpr_until_rightbracket
109+
%type<expr>expr_until_thenexpr_until_loop
109110
%type<expr>opt_exitcond
110111

111112
%type<ival>assign_varcursor_variable
@@ -822,6 +823,21 @@ assign_var: T_VARIABLE
822823
check_assignable(yylval.variable);
823824
$$ = yylval.variable->dno;
824825
}
826+
|assign_var'['expr_until_rightbracket
827+
{
828+
PLpgSQL_arrayelem*new;
829+
830+
new = malloc(sizeof(PLpgSQL_arrayelem));
831+
memset(new,0,sizeof(PLpgSQL_arrayelem));
832+
833+
new->dtype= PLPGSQL_DTYPE_ARRAYELEM;
834+
new->subscript=$3;
835+
new->arrayparentno =$1;
836+
837+
plpgsql_adddatum((PLpgSQL_datum *)new);
838+
839+
$$ =new->dno;
840+
}
825841
;
826842

827843
stmt_if:K_IFlnoexpr_until_thenproc_sectstmt_elseK_ENDK_IF';'
@@ -1491,6 +1507,10 @@ expr_until_semi :
14911507
{$$ = plpgsql_read_expression(';',";"); }
14921508
;
14931509

1510+
expr_until_rightbracket :
1511+
{$$ = plpgsql_read_expression(']',"]"); }
1512+
;
1513+
14941514
expr_until_then :
14951515
{$$ = plpgsql_read_expression(K_THEN,"THEN"); }
14961516
;
@@ -1577,16 +1597,16 @@ read_sql_construct(int until,
15771597
for (;;)
15781598
{
15791599
tok =yylex();
1580-
if (tok =='(')
1600+
if (tok == until && parenlevel ==0)
1601+
break;
1602+
if (tok =='(' || tok =='[')
15811603
parenlevel++;
1582-
elseif (tok ==')')
1604+
elseif (tok ==')' || tok ==']')
15831605
{
15841606
parenlevel--;
15851607
if (parenlevel <0)
15861608
elog(ERROR,"mismatched parentheses");
15871609
}
1588-
elseif (parenlevel ==0 && tok == until)
1589-
break;
15901610
/*
15911611
* End of function definition is an error, and we don't expect to
15921612
* hit a semicolon either (unless it's the until symbol, in which
@@ -1988,6 +2008,9 @@ check_assignable(PLpgSQL_datum *datum)
19882008
case PLPGSQL_DTYPE_RECFIELD:
19892009
/* always assignable?*/
19902010
break;
2011+
case PLPGSQL_DTYPE_ARRAYELEM:
2012+
/* always assignable?*/
2013+
break;
19912014
case PLPGSQL_DTYPE_TRIGARG:
19922015
yyerror("cannot assign to tg_argv");
19932016
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp