From 92af9143f13df8c54362ebbd4397cb53f207ff2d Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 12 Aug 2022 12:05:50 +0200 Subject: Reject MERGE in CTEs and COPY The grammar added for MERGE inadvertently made it accepted syntax in places that were not prepared to deal with it -- namely COPY and inside CTEs, but invoking these things with MERGE currently causes assertion failures or weird misbehavior in non-assertion builds. Protect those places by checking for it explicitly until somebody decides to implement it. Reported-by: Alexey Borzov Discussion: https://postgr.es/m/17579-82482cd7b267b862@postgresql.org --- src/backend/parser/parse_cte.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/backend/parser/parse_cte.c') diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c index efb4af706e1..8fc86586085 100644 --- a/src/backend/parser/parse_cte.c +++ b/src/backend/parser/parse_cte.c @@ -126,6 +126,13 @@ transformWithClause(ParseState *pstate, WithClause *withClause) CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); ListCell *rest; + /* MERGE is allowed by parser, but unimplemented. Reject for now */ + if (IsA(cte->ctequery, MergeStmt)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("MERGE not supported in WITH query"), + parser_errposition(pstate, cte->location)); + for_each_cell(rest, withClause->ctes, lnext(withClause->ctes, lc)) { CommonTableExpr *cte2 = (CommonTableExpr *) lfirst(rest); -- cgit v1.2.3