Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0A9671337B4E for ; Thu, 24 Feb 2011 20:23:02 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 11321-05 for ; Fri, 25 Feb 2011 00:22:53 +0000 (UTC) X-Greylist: delayed 00:19:05.434283 by SQLgrey-1.7.6 Received: from mail.erwied.eu (mail.erwied.eu [85.214.80.157]) by mail.postgresql.org (Postfix) with ESMTP id 8E7391337B4A for ; Thu, 24 Feb 2011 20:22:53 -0400 (AST) Received: from dslb-188-109-101-074.pools.arcor-ip.net ([188.109.101.74] helo=erwied.dns2go.com ident=mail) by mail.erwied.eu with esmtpsa (Exim 4.72#1) id 1Psl9t-0001XJ-3H ; Fri, 25 Feb 2011 01:03:45 +0100 Received: from joe-lifebook.dhcp.erwied.de ([172.17.10.70] helo=localhost) by erwied.dns2go.com with esmtpsa (Exim 4.74#1) id 1Psl9r-00071Y-0q ; Fri, 25 Feb 2011 01:03:43 +0100 Date: Fri, 25 Feb 2011 01:03:12 +0100 From: Jochen Erwied Organization: Creative Chaos Computing X-Priority: 3 (Normal) Message-ID: <1923741490.20110225010312@erwied.eu> To: Dave Crooke CC: pgsql-performance@postgresql.org Subject: Re: Possible parser bug? .... Re: Picking out the most recent row using a time stamp column In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Antivirus: avast! (VPS 110224-1, 24.02.2011), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/488 X-Sequence-Number: 42626 Friday, February 25, 2011, 12:53:08 AM you wrote: > select distinct on (a, b, c) > a, b c, time_stamp, value Without the comma, you declare 'b AS c' > from data > order by a, b, c, time_stamp desc; > The output produced is the same as this query: > select distinct on (a, b) > a, b, time_stamp, value > from data > order by a, b, time_stamp desc; the 'c' is optimized away, since it is an alias for b, and thus redundant= =20 for the distinct. > Not sure if this is considered a parser bug or not, but it feels slightly > odd not to get an error. No error, just plain SQL :-) --=20 Jochen Erwied | home: jochen@erwied.eu +49-208-38800-18, FAX: -19 Sauerbruchstr. 17 | work: joe@mbs-software.de +49-2151-7294-24, FAX: -50 D-45470 Muelheim | mobile: jochen.erwied@vodafone.de +49-173-5404164