7.9 <query specification>
让我们考虑这里指定的 SQL 标准部分:
http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt
<query specification> ::=
SELECT [ <set quantifier> ] <select list> <table expression>
[...]
<select list> ::=
<asterisk>
| <select sublist> [ { <comma> <select sublist> }... ]
[...]
Syntax Rules
1) Let T be the result of the <table expression>.
3) Case:
a) [...]
b) Otherwise, the <select list> "*" is equivalent to a <value
expression> sequence in which each <value expression> is a
<column reference> that references a column of T and each
column of T is referenced exactly once. The columns are ref-
erenced in the ascending sequence of their ordinal position
within T.
因此,换句话说,是的,SQL 标准指定要根据它们在T
. 请注意,当您<table expression>
包含多个涉及JOIN .. USING
orNATURAL JOIN
子句的表时,事情会变得有些棘手。但是,当从一个简单的表中进行选择时,假设顺序符合预期,您可能没问题。
ordinal position within T
为了完整起见, for 表的含义在下面进一步解释11.4 <column definition>
:
General Rules
5) [...] The ordinal position included
in the column descriptor is equal to the degree of T. [...]
然后在11.11 <add column definition>
(for ALTER TABLE
statements)
General Rules
4) [...] In particular, the degree of T
is increased by 1 and the ordinal position of that column is
equal to the new degree of T as specified in the General Rules
of Subclause 11.4, "<column definition>".
还有相当多的其他 SQL 语句和子句依赖于ordinal positions
within的正式规范<table expressions>
。一些例子:
13.8 <insert statement>
(when omitting the `<insert column list>`)
20.2 <direct select statement: multiple rows>
(when `<sort specification>` contains an `<unsigned integer>`)
尤其是 Postgres,它非常符合标准,所以如果你真的想要SELECT *
,请继续!