On 8/14/2013 12:59 PM, Richard Hipp wrote:
On Wed, Aug 14, 2013 at 12:22 PM, Rob Golsteijn
<[email protected]>wrote:

create table test(name);
insert into test values (NULL);
insert into test values ('abc');

select count(),
        NULLIF(name,'abc') AS name
from test
group by lower(name);


So the question is, should the "name" symbol in the GROUP BY clause refer
to the original column name in the TEST table, or should it refer to the
result column called "name".  SQLite version 3.7.15 picks the TEST table
column.  Version 3.7.17 picks the result column.

Anybody know which is correct?

For what it's worth, my reading of SQL-92 suggests that 3.7.15 is correct.

1) If no <where clause> is specified, then let T be the result of
            the preceding <from clause>; otherwise, let T be the result of
            the preceding <where clause>.
2) Each <column reference> in the <group by clause> shall unambigu-
            ously reference a column of T.

ORDER BY clause is different - column names there resolve in the context of the whole preceding SELECT statement, not just its FROM part:

 3) Let T be the table specified by the <query expression>.
 4) If ORDER BY is specified, then each <sort specification> in the
            <order by clause> shall identify a column of T.

--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to