Skip to content

Commit 65b1d76

Browse files
committed
Fix oversight in CALL argument handling, and do some minor cleanup.
CALL statements cannot support sub-SELECTs in the arguments of the called procedure, since they just use ExecEvalExpr to evaluate such arguments. Teach transformSubLink() to reject the case, as it already does for other contexts in which subqueries are not supported. In passing, s/EXPR_KIND_CALL/EXPR_KIND_CALL_ARGUMENT/ to make that enum symbol line up more closely with the phrasing of the error messages it is associated with. And fix someone's weak grasp of English grammar in the preceding EXPR_KIND_PARTITION_EXPRESSION addition. Also update an incorrect comment in resolve_unique_index_expr (possibly it was correct when written, but nowadays transformExpr definitely does reject SRFs here). Per report from Pavel Stehule --- but this resolves only one of the bugs he mentions. Discussion: https://postgr.es/m/CAFj8pRDxOwPPzpA8i+AQeDQFj7bhVw-dR2==rfWZ3zMGkm568Q@mail.gmail.com
1 parent fad15f4 commit 65b1d76

File tree

7 files changed

+19
-18
lines changed

7 files changed

+19
-18
lines changed

src/backend/commands/functioncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ ExecuteCallStmt(ParseState *pstate, CallStmt *stmt, bool atomic)
22252225
{
22262226
targs = lappend(targs, transformExpr(pstate,
22272227
(Node *) lfirst(lc),
2228-
EXPR_KIND_CALL));
2228+
EXPR_KIND_CALL_ARGUMENT));
22292229
}
22302230

22312231
node = ParseFuncOrColumn(pstate,

src/backend/parser/parse_agg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,13 @@ check_agglevels_and_constraints(ParseState *pstate, Node *expr)
509509
break;
510510
case EXPR_KIND_PARTITION_EXPRESSION:
511511
if (isAgg)
512-
err = _("aggregate functions are not allowed in partition key expression");
512+
err = _("aggregate functions are not allowed in partition key expressions");
513513
else
514-
err = _("grouping operations are not allowed in partition key expression");
514+
err = _("grouping operations are not allowed in partition key expressions");
515515

516516
break;
517517

518-
case EXPR_KIND_CALL:
518+
case EXPR_KIND_CALL_ARGUMENT:
519519
if (isAgg)
520520
err = _("aggregate functions are not allowed in CALL arguments");
521521
else
@@ -897,9 +897,9 @@ transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc,
897897
err = _("window functions are not allowed in trigger WHEN conditions");
898898
break;
899899
case EXPR_KIND_PARTITION_EXPRESSION:
900-
err = _("window functions are not allowed in partition key expression");
900+
err = _("window functions are not allowed in partition key expressions");
901901
break;
902-
case EXPR_KIND_CALL:
902+
case EXPR_KIND_CALL_ARGUMENT:
903903
err = _("window functions are not allowed in CALL arguments");
904904
break;
905905

src/backend/parser/parse_clause.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,12 +3106,11 @@ resolve_unique_index_expr(ParseState *pstate, InferClause *infer,
31063106
}
31073107

31083108
/*
3109-
* transformExpr() should have already rejected subqueries,
3110-
* aggregates, and window functions, based on the EXPR_KIND_ for an
3111-
* index expression. Expressions returning sets won't have been
3112-
* rejected, but don't bother doing so here; there should be no
3113-
* available expression unique index to match any such expression
3114-
* against anyway.
3109+
* transformExpr() will reject subqueries, aggregates, window
3110+
* functions, and SRFs, based on being passed
3111+
* EXPR_KIND_INDEX_EXPRESSION. So we needn't worry about those
3112+
* further ... not that they would match any available index
3113+
* expression anyway.
31153114
*/
31163115
pInfer->expr = transformExpr(pstate, parse, EXPR_KIND_INDEX_EXPRESSION);
31173116

src/backend/parser/parse_expr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,6 @@ transformSubLink(ParseState *pstate, SubLink *sublink)
18181818
case EXPR_KIND_RETURNING:
18191819
case EXPR_KIND_VALUES:
18201820
case EXPR_KIND_VALUES_SINGLE:
1821-
case EXPR_KIND_CALL:
18221821
/* okay */
18231822
break;
18241823
case EXPR_KIND_CHECK_CONSTRAINT:
@@ -1847,6 +1846,9 @@ transformSubLink(ParseState *pstate, SubLink *sublink)
18471846
case EXPR_KIND_PARTITION_EXPRESSION:
18481847
err = _("cannot use subquery in partition key expression");
18491848
break;
1849+
case EXPR_KIND_CALL_ARGUMENT:
1850+
err = _("cannot use subquery in CALL argument");
1851+
break;
18501852

18511853
/*
18521854
* There is intentionally no default: case here, so that the
@@ -3471,7 +3473,7 @@ ParseExprKindName(ParseExprKind exprKind)
34713473
return "WHEN";
34723474
case EXPR_KIND_PARTITION_EXPRESSION:
34733475
return "PARTITION BY";
3474-
case EXPR_KIND_CALL:
3476+
case EXPR_KIND_CALL_ARGUMENT:
34753477
return "CALL";
34763478

34773479
/*

src/backend/parser/parse_func.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ check_srf_call_placement(ParseState *pstate, Node *last_srf, int location)
22902290
case EXPR_KIND_PARTITION_EXPRESSION:
22912291
err = _("set-returning functions are not allowed in partition key expressions");
22922292
break;
2293-
case EXPR_KIND_CALL:
2293+
case EXPR_KIND_CALL_ARGUMENT:
22942294
err = _("set-returning functions are not allowed in CALL arguments");
22952295
break;
22962296

src/include/parser/parse_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef enum ParseExprKind
6969
EXPR_KIND_TRIGGER_WHEN, /* WHEN condition in CREATE TRIGGER */
7070
EXPR_KIND_POLICY, /* USING or WITH CHECK expr in policy */
7171
EXPR_KIND_PARTITION_EXPRESSION, /* PARTITION BY expression */
72-
EXPR_KIND_CALL /* CALL argument */
72+
EXPR_KIND_CALL_ARGUMENT /* procedure argument in CALL */
7373
} ParseExprKind;
7474

7575

src/test/regress/expected/create_table.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ DROP FUNCTION retset(int);
325325
CREATE TABLE partitioned (
326326
a int
327327
) PARTITION BY RANGE ((avg(a)));
328-
ERROR: aggregate functions are not allowed in partition key expression
328+
ERROR: aggregate functions are not allowed in partition key expressions
329329
CREATE TABLE partitioned (
330330
a int,
331331
b int
332332
) PARTITION BY RANGE ((avg(a) OVER (PARTITION BY b)));
333-
ERROR: window functions are not allowed in partition key expression
333+
ERROR: window functions are not allowed in partition key expressions
334334
CREATE TABLE partitioned (
335335
a int
336336
) PARTITION BY LIST ((a LIKE (SELECT 1)));

0 commit comments

Comments
 (0)