Skip to content

Instantly share code, notes, and snippets.

@krk
Created June 27, 2017 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krk/bd331cdc0c994708e444a86db2432ce8 to your computer and use it in GitHub Desktop.
Save krk/bd331cdc0c994708e444a86db2432ce8 to your computer and use it in GitHub Desktop.
/*
* 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