Re: [HACKERS] Some progress on INSERT/SELECT/GROUP BY bugs - Mailing list pgsql-hackers

From ZEUGSWETTER Andreas IZ5
Subject Re: [HACKERS] Some progress on INSERT/SELECT/GROUP BY bugs
Date
Msg-id 219F68D65015D011A8E000006F8590C60267B36D@sdexcsrv1.f000.d0188.sd.spardat.at
Whole thread Raw
List pgsql-hackers
> >
> > > I still am unclear which of these are valid SQL:
> > >
> > >  select a as b from test order by a
> > >  select a as b from test order by b
> > >
> > Both are valid, and don't forget the third variant:
> >
> > select a as b from test order by 1
> >
> > Andreas
> >
> 
>     I  wonder  why  this  should be valid. Consider the following
>     test case:
> 
>         CREATE TABLE t1 (a int4, b int4);
>         SELECT a AS b, b AS a FROM t1 GROUP BY a, b;
> 
>     Is that now GROUP BY 1,2 or BY 2,1? Without the grouping,  it
> 
The order of the columns in a group by don't affect the result.
It will affect the sort order, but without an order by, the order is 
implementation depentent and not guaranteed by ANSI. 

>     is a totally valid statement because the column DISPLAY-names
>     given with AS don't affect the rest of it.
> 
Resumee:group by and where ignores alias completely (in Oracle and Informix)order by uses alias    (only if unambiguous
inInformix, alias precedes column name
 
in Oracle)

So I guess our group by code does it different, than all others :-(

At last what about this, even if it is how the others do it, it is not
consistent with
our group by:
regression=> select a as b, b as c from a where c=3;
b|c
-+-
3|1
(1 row)

Does anyone know what standard says ?

Andreas


pgsql-hackers by date:

Previous
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] Open 6.5 items
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Open 6.5 items