Re: Window function trouble - Mailing list pgsql-sql

From Harald Fuchs
Subject Re: Window function trouble
Date
Msg-id puy6la8rw7.fsf@srv.protecting.net
Whole thread Raw
In response to Window function trouble  (Harald Fuchs <hari.fuchs@gmail.com>)
Responses Re: Window function trouble  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
In article <25983.1260468559@sss.pgh.pa.us>,
Tom Lane <tgl@sss.pgh.pa.us> writes:

> The SQL standard says the default name for any output column other
> than a simple column reference is implementation-dependent.  I think
> our implementation involves looking at the default value for a CASE.

Thanks for the clarification, Tom - so it's not a PostgreSQL bug, but
a misfeature of the SQL standard.

That being said, I still think that PostgreSQL could do better - how
about naming expression columns so that they are distinct from column
names?  The current implementation throws an error e.g. for
 SELECT adr,        CASE lag(adr) OVER (ORDER BY adr)        WHEN adr THEN NULL        ELSE adr        END,        usr,
count(*)FROM tbl WHERE host = 'h1' GROUP BY adr, usr ORDER BY adr, usr
 

namely `ORDER BY "adr" is ambiguous' which I find somewhat confusing.



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Window function trouble
Next
From: Tom Lane
Date:
Subject: Re: Window function trouble