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

Commit9b21a18

Browse files
committed
the following little patch adds array references to query
parameters. With it applied a function like CREATE FUNCTION getname(oid8, int4) RETURNS name AS 'SELECT typname FROM pg_type WHERE oid = $1[$2]' LANGUAGE 'sql'; is possible. Mainly I need this to enable array references in expressions for PL/pgSQL. Complete regression test ran O.K.Jan
1 parent772a596 commit9b21a18

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

‎src/backend/parser/gram.y

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.33 1998/09/30 05:47:56 thomas Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.34 1998/10/02 16:23:04 momjian Exp $
1414
*
1515
* HISTORY
1616
* AUTHORDATEMAJOR EVENT
@@ -4598,10 +4598,11 @@ AexprConst: Iconst
45984598
}
45994599
;
46004600

4601-
ParamNo: PARAM
4601+
ParamNo: PARAM opt_indirection
46024602
{
46034603
$$ = makeNode(ParamNo);
46044604
$$->number = $1;
4605+
$$->indirection = $2;
46054606
}
46064607
;
46074608

‎src/backend/parser/parse_expr.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.35 1998/10/01 22:51:20 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.36 1998/10/02 16:23:05 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -122,7 +122,39 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
122122
param->paramtype= (Oid)toid;
123123
param->param_tlist= (List*)NULL;
124124

125-
result= (Node*)param;
125+
if (pno->indirection!=NIL)
126+
{
127+
List*idx=pno->indirection;
128+
129+
while (idx!=NIL)
130+
{
131+
A_Indices*ai= (A_Indices*)lfirst(idx);
132+
Node*lexpr=NULL,
133+
*uexpr;
134+
135+
uexpr=transformExpr(pstate,ai->uidx,precedence);/* must exists */
136+
if (exprType(uexpr)!=INT4OID)
137+
elog(ERROR,"array index expressions must be int4's");
138+
if (ai->lidx!=NULL)
139+
{
140+
lexpr=transformExpr(pstate,ai->lidx,precedence);
141+
if (exprType(lexpr)!=INT4OID)
142+
elog(ERROR,"array index expressions must be int4's");
143+
}
144+
ai->lidx=lexpr;
145+
ai->uidx=uexpr;
146+
147+
/*
148+
* note we reuse the list of indices, make sure we
149+
* don't free them! Otherwise, make a new list
150+
* here
151+
*/
152+
idx=lnext(idx);
153+
}
154+
result= (Node*)make_array_ref((Node*)param,pno->indirection);
155+
}
156+
else
157+
result= (Node*)param;
126158
break;
127159
}
128160
caseT_A_Expr:

‎src/include/nodes/parsenodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: parsenodes.h,v 1.59 1998/09/01 04:36:43 momjian Exp $
9+
* $Id: parsenodes.h,v 1.60 1998/10/02 16:23:07 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -667,6 +667,7 @@ typedef struct ParamNo
667667
NodeTagtype;
668668
intnumber;/* the number of the parameter */
669669
TypeName*typename;/* the typecast */
670+
List*indirection;/* array references */
670671
}ParamNo;
671672

672673
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp