Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DE9486330A8 for ; Thu, 10 Dec 2009 17:02:43 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 37638-06 for ; Thu, 10 Dec 2009 21:02:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 23E98632C60 for ; Thu, 10 Dec 2009 17:02:33 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.50) id 1NIq9f-0000rN-DF for pgsql-sql@postgresql.org; Thu, 10 Dec 2009 22:02:31 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Dec 2009 22:02:31 +0100 Received: from hari.fuchs by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Dec 2009 22:02:31 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Window function trouble Date: Thu, 10 Dec 2009 22:02:00 +0100 Lines: 26 Message-ID: References: <25983.1260468559@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net X-Archive: encrypt User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:A8x4aW8fo6E22VNeY9KGy1TYzjc= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/30 X-Sequence-Number: 33468 In article <25983.1260468559@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 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.