Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/*
* Returns a subquery selecting outputColumns from main_arg.
* main_arg is modified and returned.
*/
static SelectStmt *
createSubqueryForCorresponding(List* outputColumns, SelectStmt* main_arg)
{
ColumnRef *cr;
ResTarget *rt;
SelectStmt *n;
RangeSubselect * rss;
ListCell* mctl;
n = makeNode(SelectStmt);
n->targetList = NIL;
foreach(mctl, outputColumns)
{
TargetEntry *mctle = (TargetEntry *) lfirst(mctl);
cr = makeNode(ColumnRef);
cr->fields = list_make1(makeString(mctle->resname));
cr->location = -1;
rt = makeNode(ResTarget);
rt->name = NULL;
rt->indirection = NIL;
rt->val = (Node *)cr;
rt->location = -1;
n->targetList = lappend(n->targetList, rt);
}
rss = makeNode(RangeSubselect);
// XXX makeAlias alias name should be empty??
rss->alias = makeAlias("", NULL);
rss->subquery = (Node *)main_arg;
n->fromClause = list_make1(rss);
main_arg = n;
return main_arg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment