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

Commitd43a619

Browse files
committed
Fix check_srf_call_placement() to handle VALUES cases correctly.
INSERT ... VALUES with a single VALUES row is implemented quite differentlyfrom the general VALUES case. A user-visible implication of that is thatwe accept SRFs in the single-row case, but not in the multi-row case.That's a historical artifact no doubt, but in view of the lack of fieldcomplaints, I'm not excited about fixing it right now.However, check_srf_call_placement() needs to know about this, first becauseit should throw an error in the unsupported case, and second because itshould set p_hasTargetSRFs in the single-row case (because we treat thatlike a SELECT tlist). That's an oversight in commita4c35ea.To fix, split EXPR_KIND_VALUES into two values. So far as I can see,this is the only place where we need to distinguish the two cases atpresent; but there might be more later.Patch by me, per report from Andres Freund.Discussion:https://postgr.es/m/20170116081548.zg63zltblwimpfgp@alap3.anarazel.de
1 parent4e46c97 commitd43a619

File tree

6 files changed

+15
-3
lines changed

6 files changed

+15
-3
lines changed

‎src/backend/parser/analyze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
790790
*/
791791
exprList=transformExpressionList(pstate,
792792
(List*)linitial(valuesLists),
793-
EXPR_KIND_VALUES,
793+
EXPR_KIND_VALUES_SINGLE,
794794
true);
795795

796796
/* Prepare row for assignment to target table */

‎src/backend/parser/parse_agg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ check_agglevels_and_constraints(ParseState *pstate, Node *expr)
447447
errkind= true;
448448
break;
449449
caseEXPR_KIND_VALUES:
450+
caseEXPR_KIND_VALUES_SINGLE:
450451
errkind= true;
451452
break;
452453
caseEXPR_KIND_CHECK_CONSTRAINT:
@@ -840,6 +841,7 @@ transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
840841
errkind= true;
841842
break;
842843
caseEXPR_KIND_VALUES:
844+
caseEXPR_KIND_VALUES_SINGLE:
843845
errkind= true;
844846
break;
845847
caseEXPR_KIND_CHECK_CONSTRAINT:

‎src/backend/parser/parse_expr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ transformSubLink(ParseState *pstate, SubLink *sublink)
17971797
caseEXPR_KIND_OFFSET:
17981798
caseEXPR_KIND_RETURNING:
17991799
caseEXPR_KIND_VALUES:
1800+
caseEXPR_KIND_VALUES_SINGLE:
18001801
/* okay */
18011802
break;
18021803
caseEXPR_KIND_CHECK_CONSTRAINT:
@@ -3410,6 +3411,7 @@ ParseExprKindName(ParseExprKind exprKind)
34103411
caseEXPR_KIND_RETURNING:
34113412
return"RETURNING";
34123413
caseEXPR_KIND_VALUES:
3414+
caseEXPR_KIND_VALUES_SINGLE:
34133415
return"VALUES";
34143416
caseEXPR_KIND_CHECK_CONSTRAINT:
34153417
caseEXPR_KIND_DOMAIN_CHECK:

‎src/backend/parser/parse_func.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,12 @@ check_srf_call_placement(ParseState *pstate, int location)
21412141
errkind= true;
21422142
break;
21432143
caseEXPR_KIND_VALUES:
2144-
/* okay */
2144+
/* SRFs are presently not supported by nodeValuesscan.c */
2145+
errkind= true;
2146+
break;
2147+
caseEXPR_KIND_VALUES_SINGLE:
2148+
/* okay, since we process this like a SELECT tlist */
2149+
pstate->p_hasTargetSRFs= true;
21452150
break;
21462151
caseEXPR_KIND_CHECK_CONSTRAINT:
21472152
caseEXPR_KIND_DOMAIN_CHECK:

‎src/include/parser/parse_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef enum ParseExprKind
5555
EXPR_KIND_OFFSET,/* OFFSET */
5656
EXPR_KIND_RETURNING,/* RETURNING */
5757
EXPR_KIND_VALUES,/* VALUES */
58+
EXPR_KIND_VALUES_SINGLE,/* single-row VALUES (in INSERT only) */
5859
EXPR_KIND_CHECK_CONSTRAINT,/* CHECK constraint for a table */
5960
EXPR_KIND_DOMAIN_CHECK,/* CHECK constraint for a domain */
6061
EXPR_KIND_COLUMN_DEFAULT,/* default value for a table column */

‎src/test/regress/expected/tsrf.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ LINE 1: INSERT INTO fewmore VALUES(1) RETURNING generate_series(1,3)...
374374
^
375375
-- nor standalone VALUES (but surely this is a bug?)
376376
VALUES(1, generate_series(1,2));
377-
ERROR: set-valued function called in context that cannot accept a set
377+
ERROR: set-returning functions are not allowed in VALUES
378+
LINE 1: VALUES(1, generate_series(1,2));
379+
^
378380
-- We allow tSRFs that are not at top level
379381
SELECT int4mul(generate_series(1,2), 10);
380382
int4mul

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp