Skip to content

Commit d43a619

Browse files
committed
Fix check_srf_call_placement() to handle VALUES cases correctly.
INSERT ... VALUES with a single VALUES row is implemented quite differently from the general VALUES case. A user-visible implication of that is that we 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 field complaints, I'm not excited about fixing it right now. However, check_srf_call_placement() needs to know about this, first because it should throw an error in the unsupported case, and second because it should set p_hasTargetSRFs in the single-row case (because we treat that like a SELECT tlist). That's an oversight in commit a4c35ea. 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 at present; 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 parent 4e46c97 commit d43a619

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
case EXPR_KIND_VALUES:
450+
case EXPR_KIND_VALUES_SINGLE:
450451
errkind = true;
451452
break;
452453
case EXPR_KIND_CHECK_CONSTRAINT:
@@ -840,6 +841,7 @@ transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
840841
errkind = true;
841842
break;
842843
case EXPR_KIND_VALUES:
844+
case EXPR_KIND_VALUES_SINGLE:
843845
errkind = true;
844846
break;
845847
case EXPR_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
case EXPR_KIND_OFFSET:
17981798
case EXPR_KIND_RETURNING:
17991799
case EXPR_KIND_VALUES:
1800+
case EXPR_KIND_VALUES_SINGLE:
18001801
/* okay */
18011802
break;
18021803
case EXPR_KIND_CHECK_CONSTRAINT:
@@ -3410,6 +3411,7 @@ ParseExprKindName(ParseExprKind exprKind)
34103411
case EXPR_KIND_RETURNING:
34113412
return "RETURNING";
34123413
case EXPR_KIND_VALUES:
3414+
case EXPR_KIND_VALUES_SINGLE:
34133415
return "VALUES";
34143416
case EXPR_KIND_CHECK_CONSTRAINT:
34153417
case EXPR_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
case EXPR_KIND_VALUES:
2144-
/* okay */
2144+
/* SRFs are presently not supported by nodeValuesscan.c */
2145+
errkind = true;
2146+
break;
2147+
case EXPR_KIND_VALUES_SINGLE:
2148+
/* okay, since we process this like a SELECT tlist */
2149+
pstate->p_hasTargetSRFs = true;
21452150
break;
21462151
case EXPR_KIND_CHECK_CONSTRAINT:
21472152
case EXPR_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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy