Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
else if(linitial(stmt->correspondingClause) == NULL)
{
// CORRESPONDING clause, find matching column names from both tables. If there are none then it is a syntax error.
Query *largQuery;
Query *rargQuery;
List *matchingColumns;
/* Analyze left query to resolve column names. */
largQuery = parse_sub_analyze((Node *) stmt->larg, pstate, NULL, false);
/* Analyze right query to resolve column names. */
rargQuery = parse_sub_analyze((Node *) stmt->rarg, pstate, NULL, false);
/* Find matching columns from both queries. */
matchingColumns = determineMatchingColumns(largQuery->targetList,
rargQuery->targetList);
op->correspondingColumns = matchingColumns;
op->hasCorrespondingBy = false;
/* If matchingColumns is empty, there is an error. At least one column in the select lists must have the same name. */
if(list_length(matchingColumns) == 0)
{
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("%s queries with a CORRESPONDING clause must have at least one column with the same name",
context)));
}
// Create subquery for larg, selecting column names from matchingColumns.
stmt->larg = createSubqueryForCorresponding(matchingColumns, stmt->larg);
// Assign newly generated query to original left query.
op->larg = transformSetOperationTree(pstate, stmt->larg,
false,
<argetlist);
// Create subquery for rarg, selecting column names from matchingColumns.
stmt->rarg = createSubqueryForCorresponding(matchingColumns, stmt->rarg);
// Assign newly generated query to original right query.
op->rarg = transformSetOperationTree(pstate, stmt->rarg,
false,
&rtargetlist);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment