diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-11-21 19:37:02 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-11-21 19:37:20 -0500 |
commit | 784e762e886e6f72f548da86a27cd2ead87dbd1c (patch) | |
tree | 9c21fc1545c96a655ec4591e1ba3c8d99cdfccf8 /src/backend/nodes/nodeFuncs.c | |
parent | 38f432898131270e5b64245786cb67f322538bae (diff) | |
download | postgresql-784e762e886e6f72f548da86a27cd2ead87dbd1c.tar.gz postgresql-784e762e886e6f72f548da86a27cd2ead87dbd1c.zip |
Support multi-argument UNNEST(), and TABLE() syntax for multiple functions.
This patch adds the ability to write TABLE( function1(), function2(), ...)
as a single FROM-clause entry. The result is the concatenation of the
first row from each function, followed by the second row from each
function, etc; with NULLs inserted if any function produces fewer rows than
others. This is believed to be a much more useful behavior than what
Postgres currently does with multiple SRFs in a SELECT list.
This syntax also provides a reasonable way to combine use of column
definition lists with WITH ORDINALITY: put the column definition list
inside TABLE(), where it's clear that it doesn't control the ordinality
column as well.
Also implement SQL-compliant multiple-argument UNNEST(), by turning
UNNEST(a,b,c) into TABLE(unnest(a), unnest(b), unnest(c)).
The SQL standard specifies TABLE() with only a single function, not
multiple functions, and it seems to require an implicit UNNEST() which is
not what this patch does. There may be something wrong with that reading
of the spec, though, because if it's right then the spec's TABLE() is just
a pointless alternative spelling of UNNEST(). After further review of
that, we might choose to adopt a different syntax for what this patch does,
but in any case this functionality seems clearly worthwhile.
Andrew Gierth, reviewed by Zoltán Böszörményi and Heikki Linnakangas, and
significantly revised by me
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r-- | src/backend/nodes/nodeFuncs.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 908f397d501..d7db67dc9ea 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -1447,6 +1447,9 @@ exprLocation(const Node *expr) case T_TypeName: loc = ((const TypeName *) expr)->location; break; + case T_ColumnDef: + loc = ((const ColumnDef *) expr)->location; + break; case T_Constraint: loc = ((const Constraint *) expr)->location; break; @@ -1901,6 +1904,8 @@ expression_tree_walker(Node *node, break; case T_PlaceHolderInfo: return walker(((PlaceHolderInfo *) node)->ph_var, context); + case T_RangeTblFunction: + return walker(((RangeTblFunction *) node)->funcexpr, context); default: elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node)); @@ -2000,7 +2005,7 @@ range_table_walker(List *rtable, return true; break; case RTE_FUNCTION: - if (walker(rte->funcexpr, context)) + if (walker(rte->functions, context)) return true; break; case RTE_VALUES: @@ -2615,6 +2620,17 @@ expression_tree_mutator(Node *node, return (Node *) newnode; } break; + case T_RangeTblFunction: + { + RangeTblFunction *rtfunc = (RangeTblFunction *) node; + RangeTblFunction *newnode; + + FLATCOPY(newnode, rtfunc, RangeTblFunction); + MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *); + /* Assume we need not copy the coldef info lists */ + return (Node *) newnode; + } + break; default: elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node)); @@ -2725,7 +2741,7 @@ range_table_mutator(List *rtable, } break; case RTE_FUNCTION: - MUTATE(newrte->funcexpr, rte->funcexpr, Node *); + MUTATE(newrte->functions, rte->functions, List *); break; case RTE_VALUES: MUTATE(newrte->values_lists, rte->values_lists, List *); @@ -3113,10 +3129,12 @@ raw_expression_tree_walker(Node *node, { RangeFunction *rf = (RangeFunction *) node; - if (walker(rf->funccallnode, context)) + if (walker(rf->functions, context)) return true; if (walker(rf->alias, context)) return true; + if (walker(rf->coldeflist, context)) + return true; } break; case T_TypeName: |