pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
column alias and group by/having/order
3+ messages / 3 participants
[nested] [flat]

* column alias and group by/having/order
@ 2004-02-13 13:34 Tomasz Myrta <jasiek@klaster.net>
  2004-02-13 14:09 ` Re: column alias and group by/having/order Rod Taylor <pg@rbt.ca>
  2004-02-13 15:15 ` Re: column alias and group by/having/order Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 3+ messages in thread

From: Tomasz Myrta @ 2004-02-13 13:34 UTC (permalink / raw)
  To: pgsql-sql

Hi
I found some strange column alias behaviour:

select val1+val2 as val
from some_table
group by val;

result - OK

select val1+val2 as val
from some_table
order by val;

result - OK

select val1+val2 as val
from some_table
group by val having val1+val2>1;

result - OK

select val1+val2 as val
from some_table
group by val having val>1;
ERROR:  Attribute "val" not found

Is it a bug or a feature?

Regards,
Tomasz Myrta

----------------------------------------------------------------------------------------------------------------
  PostgreSQL 7.3.4 on i386-pc-linux-gnu, compiled by GCC i386-linux-gcc 
(GCC) 3.3.2 20031005 (Debian prerelease)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: column alias and group by/having/order
  2004-02-13 13:34 column alias and group by/having/order Tomasz Myrta <jasiek@klaster.net>
@ 2004-02-13 14:09 ` Rod Taylor <pg@rbt.ca>
  1 sibling, 0 replies; 3+ messages in thread

From: Rod Taylor @ 2004-02-13 14:09 UTC (permalink / raw)
  To: Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql

> select val1+val2 as val
> from some_table
> group by val having val>1;
> ERROR:  Attribute "val" not found
> 
> Is it a bug or a feature?

It's a mis-feature that group by accepts aliases of the select list.

Having is proper.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: column alias and group by/having/order
  2004-02-13 13:34 column alias and group by/having/order Tomasz Myrta <jasiek@klaster.net>
@ 2004-02-13 15:15 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2004-02-13 15:15 UTC (permalink / raw)
  To: Tomasz Myrta <jasiek@klaster.net>; +Cc: pgsql-sql

Tomasz Myrta <jasiek@klaster.net> writes:
> I found some strange column alias behaviour:

That's how it is.  The fact that you can reference output-column aliases
at all in GROUP BY or ORDER BY is a wart, because it conflicts with the
logical model of query evaluation --- the output list should be computed
last.  We have extended the SQL92 requirement (unadorned aliases in
ORDER BY) to allow the same in GROUP BY, but we don't take it to the
level of allowing them inside arbitrary expressions.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-02-13 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-13 13:34 column alias and group by/having/order Tomasz Myrta <jasiek@klaster.net>
2004-02-13 14:09 ` Rod Taylor <pg@rbt.ca>
2004-02-13 15:15 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox