Re: [SQL] Window function trouble

2009-12-10 Thread Tom Lane
Harald Fuchs writes: > That being said, I still think that PostgreSQL could do better - how > about naming expression columns so that they are distinct from column > names? Even though the rules we use are pretty arbitrary, I'm hesitant to make changes in them; it seems more likely to break exist

Re: [SQL] Window function trouble

2009-12-10 Thread Harald Fuchs
In article <25983.1260468...@sss.pgh.pa.us>, Tom Lane 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 clarific

Re: [SQL] Window function trouble

2009-12-10 Thread Tom Lane
Harald Fuchs writes: > Apparently the CASE expression is named "adr" unless named > otherwise, and the result set is sorted by this expression instead of > the column named "adr". Does anyone know what the SQL standard says > about that? The SQL standard says the default name for any output colu

Re: [SQL] Window function trouble

2009-12-10 Thread Harald Fuchs
In article , Harald Fuchs writes: > The other users for one address are gone. Does anyone know why? Update: they are not gone, but they've moved to the end of the result set. Apparently the CASE expression is named "adr" unless named otherwise, and the result set is sorted by this expression in

[SQL] Window function trouble

2009-12-10 Thread Harald Fuchs
I have a table like this: CREATE TABLE tbl ( host text NOT NULL, adr ip4 NOT NULL, usr text NOT NULL ); (ip4 is from the ip4r contrib module) and I want the number of entries per address and per user: SELECT adr, usr, count(*) FROM tbl WHERE host = ? AND adr <<= ? GRO