Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERGE: In deparser, add missing check for RETURNING clause. #6733

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/backend/distributed/deparser/ruleutils_15.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "common/keywords.h"
#include "distributed/citus_nodefuncs.h"
#include "distributed/citus_ruleutils.h"
#include "distributed/multi_router_planner.h"
#include "executor/spi.h"
#include "foreign/foreign.h"
#include "funcapi.h"
Expand Down Expand Up @@ -3723,15 +3724,14 @@ static void
get_merge_query_def(Query *query, deparse_context *context)
{
StringInfo buf = context->buf;
RangeTblEntry *targetRte;

/* Insert the WITH clause if given */
get_with_clause(query, context);

/*
* Start the query with MERGE INTO <target>
*/
targetRte = rt_fetch(query->resultRelation, query->rtable);
RangeTblEntry *targetRte = ExtractResultRelationRTE(query);

if (PRETTY_INDENT(context))
{
Expand Down Expand Up @@ -3853,6 +3853,15 @@ get_merge_query_def(Query *query, deparse_context *context)
}
}

/*
* RETURNING is not supported in MERGE, so it must be NULL, but if PG adds it later,
* we might miss it, let's raise an exception to investigate.
*/
if (unlikely(query->returningList))
{
elog(ERROR, "Unexpected RETURNING clause in MERGE");
}

ereport(DEBUG1, (errmsg("<Deparsed MERGE query: %s>", buf->data)));
}

Expand Down