AW: [HACKERS] SELECT ... AS ... names in WHERE/GROUP BY/HAVING - Mailing list pgsql-hackers

From Zeugswetter Andreas SB
Subject AW: [HACKERS] SELECT ... AS ... names in WHERE/GROUP BY/HAVING
Date
Msg-id 219F68D65015D011A8E000006F8590C603FDC1C6@sdexcsrv1.f000.d0188.sd.spardat.at
Whole thread Raw
List pgsql-hackers
> Next question is, do we want to leave the code as-is, or tighten up
> the parser to reject AS-names and column numbers in GROUP BY?

The numbers are also allowed in other DBMS's, so I would leave that as is.

> It seems to me we should change it, because there are cases where the
> existing code will do the wrong thing according to the SQL spec.
> If "foo" is a column name and also an AS-name for something else,
> "GROUP BY foo" should group on the raw column according to the spec,
> but right now we will pick the SELECT result value instead.

This of course should be handeled the other way around.
Imho the feature to use the AS-names is too convenient,
to drop it alltogether. Remember, that the lable could stand for
a complete subselect, and writing the same subselect again and
again is quite bad for readability.
I would rather extend this AS-names capability to the where
and having clause too.

select
(select max(colname) from syscolumns cwhere c.tabid = systables.tabid) as collabel
from systables
where tabname='systables' and collabel matches 'n*';

is imho a very nice and readable syntax .

Andreas


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] AND &&
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] dumpall prob