Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53685d7

Browse files
committed
Rename TABLE() to ROWS FROM().
SQL-standard TABLE() is a subset of UNNEST(); they deal with arrays andother collection types. This feature, however, deals with set-returningfunctions. Use a different syntax for this feature to keep open thepossibility of implementing the standard TABLE().
1 parent01cc1fe commit53685d7

File tree

11 files changed

+123
-123
lines changed

11 files changed

+123
-123
lines changed

‎doc/src/sgml/queries.sgml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,15 +647,15 @@ FROM (VALUES ('anne', 'smith'), ('bob', 'jones'), ('joe', 'blow'))
647647
</para>
648648

649649
<para>
650-
Table functions may also be combined using the <literal>TABLE</literal>
650+
Table functions may also be combined using the <literal>ROWS FROM</>
651651
syntax, with the results returned in parallel columns; the number of
652652
result rows in this case is that of the largest function result, with
653653
smaller results padded with NULLs to match.
654654
</para>
655655

656656
<synopsis>
657657
<replaceable>function_call</replaceable> <optional>WITH ORDINALITY</optional> <optional><optional>AS</optional> <replaceable>table_alias</replaceable> <optional>(<replaceable>column_alias</replaceable> <optional>, ... </optional>)</optional></optional>
658-
TABLE( <replaceable>function_call</replaceable> <optional>, ... </optional> ) <optional>WITH ORDINALITY</optional> <optional><optional>AS</optional> <replaceable>table_alias</replaceable> <optional>(<replaceable>column_alias</replaceable> <optional>, ... </optional>)</optional></optional>
658+
ROWS FROM( <replaceable>function_call</replaceable> <optional>, ... </optional> ) <optional>WITH ORDINALITY</optional> <optional><optional>AS</optional> <replaceable>table_alias</replaceable> <optional>(<replaceable>column_alias</replaceable> <optional>, ... </optional>)</optional></optional>
659659
</synopsis>
660660

661661
<para>
@@ -674,7 +674,7 @@ TABLE( <replaceable>function_call</replaceable> <optional>, ... </optional> ) <o
674674
any number of array parameters, and it returns a corresponding number of
675675
columns, as if <literal>UNNEST</literal>
676676
(<xref linkend="functions-array">) had been called on each parameter
677-
separately and combined using the <literal>TABLE</literal> construct.
677+
separately and combined using the <literal>ROWS FROM</literal> construct.
678678
</para>
679679

680680
<synopsis>
@@ -683,7 +683,7 @@ UNNEST( <replaceable>array_expression</replaceable> <optional>, ... </optional>
683683

684684
<para>
685685
If no <replaceable>table_alias</replaceable> is specified, the function
686-
name is used as the table name; in the case of a <literal>TABLE()</>
686+
name is used as the table name; in the case of a <literal>ROWS FROM()</>
687687
construct, the first function's name is used.
688688
</para>
689689

@@ -731,20 +731,20 @@ SELECT * FROM vw_getfoo;
731731
<synopsis>
732732
<replaceable>function_call</replaceable> <optional>AS</optional> <replaceable>alias</replaceable> (<replaceable>column_definition</replaceable> <optional>, ... </optional>)
733733
<replaceable>function_call</replaceable> AS <optional><replaceable>alias</replaceable></optional> (<replaceable>column_definition</replaceable> <optional>, ... </optional>)
734-
TABLE( ... <replaceable>function_call</replaceable> AS (<replaceable>column_definition</replaceable> <optional>, ... </optional>) <optional>, ... </optional> )
734+
ROWS FROM( ... <replaceable>function_call</replaceable> AS (<replaceable>column_definition</replaceable> <optional>, ... </optional>) <optional>, ... </optional> )
735735
</synopsis>
736736

737737
<para>
738-
When not using the <literal>TABLE()</> syntax,
738+
When not using the <literal>ROWS FROM()</> syntax,
739739
the <replaceable>column_definition</replaceable> list replaces the column
740740
alias list that could otherwise be attached to the <literal>FROM</>
741741
item; the names in the column definitions serve as column aliases.
742-
When using the <literal>TABLE()</> syntax,
742+
When using the <literal>ROWS FROM()</> syntax,
743743
a <replaceable>column_definition</replaceable> list can be attached to
744744
each member function separately; or if there is only one member function
745745
and no <literal>WITH ORDINALITY</> clause,
746746
a <replaceable>column_definition</replaceable> list can be written in
747-
place of a column alias list following <literal>TABLE()</>.
747+
place of a column alias list following <literal>ROWS FROM()</>.
748748
</para>
749749

750750
<para>

‎doc/src/sgml/ref/select.sgml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SELECT [ ALL | DISTINCT [ ON ( <replaceable class="parameter">expression</replac
5656
[ WITH ORDINALITY ] [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
5757
[ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ] <replaceable class="parameter">alias</replaceable> ( <replaceable class="parameter">column_definition</replaceable> [, ...] )
5858
[ LATERAL ] <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] )
59-
[ LATERAL ]TABLE( <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] ) ] [, ...] )
59+
[ LATERAL ]ROWS FROM( <replaceable class="parameter">function_name</replaceable> ( [ <replaceable class="parameter">argument</replaceable> [, ...] ] ) [ AS ( <replaceable class="parameter">column_definition</replaceable> [, ...] ) ] [, ...] )
6060
[ WITH ORDINALITY ] [ [ AS ] <replaceable class="parameter">alias</replaceable> [ ( <replaceable class="parameter">column_alias</replaceable> [, ...] ) ] ]
6161
<replaceable class="parameter">from_item</replaceable> [ NATURAL ] <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable> [ ON <replaceable class="parameter">join_condition</replaceable> | USING ( <replaceable class="parameter">join_column</replaceable> [, ...] ) ]
6262

@@ -390,7 +390,7 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
390390
<para>
391391
Multiple function calls can be combined into a
392392
single <literal>FROM</>-clause item by surrounding them
393-
with <literal>TABLE( ... )</>. The output of such an item is the
393+
with <literal>ROWS FROM( ... )</>. The output of such an item is the
394394
concatenation of the first row from each function, then the second
395395
row from each function, etc. If some of the functions produce fewer
396396
rows than others, NULLs are substituted for the missing data, so
@@ -410,18 +410,18 @@ TABLE [ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ]
410410
</para>
411411

412412
<para>
413-
When using the <literal>TABLE( ... )</> syntax, if one of the
413+
When using the <literal>ROWS FROM( ... )</> syntax, if one of the
414414
functions requires a column definition list, it's preferred to put
415415
the column definition list after the function call inside
416-
<literal>TABLE( ... )</>. A column definition list can be placed
417-
after the <literal>TABLE( ... )</> construct only if there's just a
418-
single function and no <literal>WITH ORDINALITY</> clause.
416+
<literal>ROWS FROM( ... )</>. A column definition list can be placed
417+
after the <literal>ROWS FROM( ... )</> construct only if there's just
418+
asingle function and no <literal>WITH ORDINALITY</> clause.
419419
</para>
420420

421421
<para>
422422
To use <literal>ORDINALITY</literal> together with a column definition
423-
list, you must use the <literal>TABLE( ... )</> syntax and put the
424-
column definition list inside <literal>TABLE( ... )</>.
423+
list, you must use the <literal>ROWS FROM( ... )</> syntax and put the
424+
column definition list inside <literal>ROWS FROM( ... )</>.
425425
</para>
426426
</listitem>
427427
</varlistentry>
@@ -1811,8 +1811,7 @@ SELECT distributors.* WHERE distributors.name = 'Westward';
18111811
</para>
18121812

18131813
<para>
1814-
Placing multiple function calls inside <literal>TABLE( ... )</> syntax is
1815-
also an extension of the SQL standard.
1814+
<literal>ROWS FROM( ... )</> is an extension of the SQL standard.
18161815
</para>
18171816
</refsect2>
18181817

‎src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ _copyRangeFunction(const RangeFunction *from)
23102310

23112311
COPY_SCALAR_FIELD(lateral);
23122312
COPY_SCALAR_FIELD(ordinality);
2313-
COPY_SCALAR_FIELD(is_table);
2313+
COPY_SCALAR_FIELD(is_rowsfrom);
23142314
COPY_NODE_FIELD(functions);
23152315
COPY_NODE_FIELD(alias);
23162316
COPY_NODE_FIELD(coldeflist);

‎src/backend/nodes/equalfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ _equalRangeFunction(const RangeFunction *a, const RangeFunction *b)
21422142
{
21432143
COMPARE_SCALAR_FIELD(lateral);
21442144
COMPARE_SCALAR_FIELD(ordinality);
2145-
COMPARE_SCALAR_FIELD(is_table);
2145+
COMPARE_SCALAR_FIELD(is_rowsfrom);
21462146
COMPARE_NODE_FIELD(functions);
21472147
COMPARE_NODE_FIELD(alias);
21482148
COMPARE_NODE_FIELD(coldeflist);

‎src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ _outRangeFunction(StringInfo str, const RangeFunction *node)
26292629

26302630
WRITE_BOOL_FIELD(lateral);
26312631
WRITE_BOOL_FIELD(ordinality);
2632-
WRITE_BOOL_FIELD(is_table);
2632+
WRITE_BOOL_FIELD(is_rowsfrom);
26332633
WRITE_NODE_FIELD(functions);
26342634
WRITE_NODE_FIELD(alias);
26352635
WRITE_NODE_FIELD(coldeflist);

‎src/backend/parser/gram.y

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
406406
a_exprb_exprc_exprAexprConstindirection_el
407407
columnrefin_exprhaving_clausefunc_tablearray_expr
408408
ExclusionWhereClause
409-
%type<list>func_table_itemfunc_table_listopt_col_def_list
409+
%type<list>rowsfrom_itemrowsfrom_listopt_col_def_list
410410
%type<boolean>opt_ordinality
411411
%type<list>ExclusionConstraintListExclusionConstraintElem
412412
%type<list>func_arg_list
@@ -9980,13 +9980,13 @@ relation_expr_opt_alias: relation_expr%prec UMINUS
99809980

99819981
/*
99829982
* func_table represents a function invocation in a FROM list. It can be
9983-
* a plain function call, like "foo(...)", or aTABLE expression with
9984-
* one or more function calls, "TABLE (foo(...), bar(...))",
9983+
* a plain function call, like "foo(...)", or aROWS FROM expression with
9984+
* one or more function calls, "ROWS FROM (foo(...), bar(...))",
99859985
* optionally with WITH ORDINALITY attached.
9986-
* In theTABLE syntax, a column definition list can be given for each
9986+
* In theROWS FROM syntax, a column definition list can be given for each
99879987
* function, for example:
9988-
*TABLE (foo() AS (foo_res_a text, foo_res_b text),
9989-
* bar() AS (bar_res_a text, bar_res_b text))
9988+
*ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
9989+
*bar() AS (bar_res_a text, bar_res_b text))
99909990
* It's also possible to attach a column definition list to the RangeFunction
99919991
* as a whole, but that's handled by the table_ref production.
99929992
*/
@@ -9995,29 +9995,30 @@ func_table: func_expr_windowless opt_ordinality
99959995
RangeFunction *n = makeNode(RangeFunction);
99969996
n->lateral =false;
99979997
n->ordinality =$2;
9998-
n->is_table =false;
9998+
n->is_rowsfrom =false;
99999999
n->functions = list_make1(list_make2($1, NIL));
1000010000
/* alias and coldeflist are set by table_ref production*/
1000110001
$$ = (Node *) n;
1000210002
}
10003-
|TABLE'('func_table_list')'opt_ordinality
10003+
|ROWSFROM'('rowsfrom_list')'opt_ordinality
1000410004
{
1000510005
RangeFunction *n = makeNode(RangeFunction);
1000610006
n->lateral =false;
10007-
n->ordinality =$5;
10008-
n->is_table =true;
10009-
n->functions =$3;
10007+
n->ordinality =$6;
10008+
n->is_rowsfrom =true;
10009+
n->functions =$4;
1001010010
/* alias and coldeflist are set by table_ref production*/
1001110011
$$ = (Node *) n;
1001210012
}
1001310013
;
1001410014

10015-
func_table_item:func_expr_windowlessopt_col_def_list
10015+
rowsfrom_item:func_expr_windowlessopt_col_def_list
1001610016
{$$ = list_make2($1,$2); }
1001710017
;
1001810018

10019-
func_table_list:func_table_item{$$ = list_make1($1); }
10020-
|func_table_list','func_table_item{$$ = lappend($1,$3); }
10019+
rowsfrom_list:
10020+
rowsfrom_item{$$ = list_make1($1); }
10021+
|rowsfrom_list','rowsfrom_item{$$ = lappend($1,$3); }
1002110022
;
1002210023

1002310024
opt_col_def_list:AS'('TableFuncElementList')'{$$ =$3; }

‎src/backend/parser/parse_clause.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,33 +655,33 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r)
655655
* expansion) and no WITH ORDINALITY. The reason for the latter
656656
* restriction is that it's not real clear whether the ordinality column
657657
* should be in the coldeflist, and users are too likely to make mistakes
658-
* in one direction or the other. Putting the coldeflist insideTABLE()
659-
* is much clearer in this case.
658+
* in one direction or the other. Putting the coldeflist insideROWS
659+
*FROM()is much clearer in this case.
660660
*/
661661
if (r->coldeflist)
662662
{
663663
if (list_length(funcexprs)!=1)
664664
{
665-
if (r->is_table)
665+
if (r->is_rowsfrom)
666666
ereport(ERROR,
667667
(errcode(ERRCODE_SYNTAX_ERROR),
668-
errmsg("TABLE() with multiple functions cannot have a column definition list"),
669-
errhint("Put a separate column definition list for each function insideTABLE()."),
668+
errmsg("ROWS FROM() with multiple functions cannot have a column definition list"),
669+
errhint("Put a separate column definition list for each function insideROWS FROM()."),
670670
parser_errposition(pstate,
671671
exprLocation((Node*)r->coldeflist))));
672672
else
673673
ereport(ERROR,
674674
(errcode(ERRCODE_SYNTAX_ERROR),
675675
errmsg("UNNEST() with multiple arguments cannot have a column definition list"),
676-
errhint("Use separate UNNEST() calls insideTABLE(), and attach a column definition list to each one."),
676+
errhint("Use separate UNNEST() calls insideROWS FROM(), and attach a column definition list to each one."),
677677
parser_errposition(pstate,
678678
exprLocation((Node*)r->coldeflist))));
679679
}
680680
if (r->ordinality)
681681
ereport(ERROR,
682682
(errcode(ERRCODE_SYNTAX_ERROR),
683683
errmsg("WITH ORDINALITY cannot be used with a column definition list"),
684-
errhint("Put the column definition list insideTABLE()."),
684+
errhint("Put the column definition list insideROWS FROM()."),
685685
parser_errposition(pstate,
686686
exprLocation((Node*)r->coldeflist))));
687687

‎src/backend/utils/adt/ruleutils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8125,10 +8125,10 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
81258125
rtfunc1= (RangeTblFunction*)linitial(rte->functions);
81268126

81278127
/*
8128-
* OmitTABLE() syntaxif there's just one function, unless it
8128+
* OmitROWS FROM() syntaxfor just one function, unless it
81298129
* has both a coldeflist and WITH ORDINALITY. If it has both,
8130-
* we must useTABLE() syntax to avoid ambiguity about whether
8131-
* the coldeflist includes the ordinality column.
8130+
* we must useROWS FROM() syntax to avoid ambiguity about
8131+
*whetherthe coldeflist includes the ordinality column.
81328132
*/
81338133
if (list_length(rte->functions)==1&&
81348134
(rtfunc1->funccolnames==NIL|| !rte->funcordinality))
@@ -8151,8 +8151,8 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
81518151
* XXX This is pretty ugly, since it makes not-terribly-
81528152
* future-proof assumptions about what the parser would do
81538153
* with the output; but the alternative is to emit our
8154-
* nonstandardextended TABLE() notation for what might
8155-
*havebeen a perfectly spec-compliant multi-argument
8154+
* nonstandardROWS FROM() notation for what might have
8155+
* been a perfectly spec-compliant multi-argument
81568156
* UNNEST().
81578157
*/
81588158
all_unnest= true;
@@ -8189,7 +8189,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
81898189
{
81908190
intfuncno=0;
81918191

8192-
appendStringInfoString(buf,"TABLE(");
8192+
appendStringInfoString(buf,"ROWS FROM(");
81938193
foreach(lc,rte->functions)
81948194
{
81958195
RangeTblFunction*rtfunc= (RangeTblFunction*)lfirst(lc);
@@ -8422,7 +8422,7 @@ get_column_alias_list(deparse_columns *colinfo, deparse_context *context)
84228422
*
84238423
* When printing a top-level coldeflist (which is syntactically also the
84248424
* relation's column alias list), use column names from colinfo. But when
8425-
* printing a coldeflist embedded insideTABLE(), we prefer to use the
8425+
* printing a coldeflist embedded insideROWS FROM(), we prefer to use the
84268426
* original coldeflist's names, which are available in rtfunc->funccolnames.
84278427
* Pass NULL for colinfo to select the latter behavior.
84288428
*

‎src/include/nodes/parsenodes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,11 @@ typedef struct RangeSubselect
466466
* RangeFunction - function call appearing in a FROM clause
467467
*
468468
* functions is a List because we use this to represent the construct
469-
*TABLE(func1(...), func2(...), ...).Each element of this list is a
469+
*ROWS FROM(func1(...), func2(...), ...).Each element of this list is a
470470
* two-element sublist, the first element being the untransformed function
471471
* call tree, and the second element being a possibly-empty list of ColumnDef
472472
* nodes representing any columndef list attached to that function within the
473-
*TABLE() syntax.
473+
*ROWS FROM() syntax.
474474
*
475475
* alias and coldeflist represent any alias and/or columndef list attached
476476
* at the top level. (We disallow coldeflist appearing both here and
@@ -481,7 +481,7 @@ typedef struct RangeFunction
481481
NodeTagtype;
482482
boollateral;/* does it have LATERAL prefix? */
483483
boolordinality;/* does it have WITH ORDINALITY suffix? */
484-
boolis_table;/* is result ofTABLE() syntax? */
484+
boolis_rowsfrom;/* is result ofROWS FROM() syntax? */
485485
List*functions;/* per-function information, see above */
486486
Alias*alias;/* table alias & optional column aliases */
487487
List*coldeflist;/* list of ColumnDef nodes to describe result

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp