mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
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 <borz_off@cs.msu.su> Discussion: https://postgr.es/m/17579-82482cd7b267b862@postgresql.org
This commit is contained in:
parent
e7a552f303
commit
92af9143f1
@ -273,6 +273,12 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
|
|||||||
{
|
{
|
||||||
Assert(stmt->query);
|
Assert(stmt->query);
|
||||||
|
|
||||||
|
/* MERGE is allowed by parser, but unimplemented. Reject for now */
|
||||||
|
if (IsA(stmt->query, MergeStmt))
|
||||||
|
ereport(ERROR,
|
||||||
|
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("MERGE not supported in COPY"));
|
||||||
|
|
||||||
query = makeNode(RawStmt);
|
query = makeNode(RawStmt);
|
||||||
query->stmt = stmt->query;
|
query->stmt = stmt->query;
|
||||||
query->stmt_location = stmt_location;
|
query->stmt_location = stmt_location;
|
||||||
|
@ -126,6 +126,13 @@ transformWithClause(ParseState *pstate, WithClause *withClause)
|
|||||||
CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
|
CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
|
||||||
ListCell *rest;
|
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))
|
for_each_cell(rest, withClause->ctes, lnext(withClause->ctes, lc))
|
||||||
{
|
{
|
||||||
CommonTableExpr *cte2 = (CommonTableExpr *) lfirst(rest);
|
CommonTableExpr *cte2 = (CommonTableExpr *) lfirst(rest);
|
||||||
|
@ -123,6 +123,20 @@ ON tid = tid
|
|||||||
WHEN MATCHED THEN DO NOTHING;
|
WHEN MATCHED THEN DO NOTHING;
|
||||||
ERROR: name "target" specified more than once
|
ERROR: name "target" specified more than once
|
||||||
DETAIL: The name is used both as MERGE target table and data source.
|
DETAIL: The name is used both as MERGE target table and data source.
|
||||||
|
-- used in a CTE
|
||||||
|
WITH foo AS (
|
||||||
|
MERGE INTO target USING source ON (true)
|
||||||
|
WHEN MATCHED THEN DELETE
|
||||||
|
) SELECT * FROM foo;
|
||||||
|
ERROR: MERGE not supported in WITH query
|
||||||
|
LINE 1: WITH foo AS (
|
||||||
|
^
|
||||||
|
-- used in COPY
|
||||||
|
COPY (
|
||||||
|
MERGE INTO target USING source ON (true)
|
||||||
|
WHEN MATCHED THEN DELETE
|
||||||
|
) TO stdout;
|
||||||
|
ERROR: MERGE not supported in COPY
|
||||||
-- unsupported relation types
|
-- unsupported relation types
|
||||||
-- view
|
-- view
|
||||||
CREATE VIEW tv AS SELECT * FROM target;
|
CREATE VIEW tv AS SELECT * FROM target;
|
||||||
|
@ -88,6 +88,16 @@ MERGE INTO target
|
|||||||
USING target
|
USING target
|
||||||
ON tid = tid
|
ON tid = tid
|
||||||
WHEN MATCHED THEN DO NOTHING;
|
WHEN MATCHED THEN DO NOTHING;
|
||||||
|
-- used in a CTE
|
||||||
|
WITH foo AS (
|
||||||
|
MERGE INTO target USING source ON (true)
|
||||||
|
WHEN MATCHED THEN DELETE
|
||||||
|
) SELECT * FROM foo;
|
||||||
|
-- used in COPY
|
||||||
|
COPY (
|
||||||
|
MERGE INTO target USING source ON (true)
|
||||||
|
WHEN MATCHED THEN DELETE
|
||||||
|
) TO stdout;
|
||||||
|
|
||||||
-- unsupported relation types
|
-- unsupported relation types
|
||||||
-- view
|
-- view
|
||||||
|
Loading…
x
Reference in New Issue
Block a user