Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 2069A632A95 for ; Sun, 18 Oct 2009 13:52:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84469-08 for ; Sun, 18 Oct 2009 16:52:07 +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 042DC63306C for ; Sun, 18 Oct 2009 13:52:06 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.50) id 1MzYzD-0000bI-5U for pgsql-sql@postgresql.org; Sun, 18 Oct 2009 18:52:03 +0200 Received: from e177157025.adsl.alicedsl.de ([85.177.157.25]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 18 Oct 2009 18:52:03 +0200 Received: from tim by e177157025.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 18 Oct 2009 18:52:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-sql@postgresql.org To: pgsql-sql@postgresql.org From: Tim Landscheidt Subject: Re: Lag and lead window functions order by weirdness Date: Sun, 18 Oct 2009 16:51:38 +0000 Organization: Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e177157025.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:N9ZOxt3BKg/0eqC3jGY+8hSL/ys= 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: 200910/69 X-Sequence-Number: 33268 Thom Brown wrote: > [...] > Having a look around, it looks as if Postgres might be misbehaving. > According to this page, > http://my.safaribooksonline.com/0596004818/sqlnut2-CHP-4-SECT-3, the ORDER > BY in the window function's clause shouldn't be having this ordering effect: > "Furthermore, the order within these groups is defined by an ordering > clause, but that order only affects function evaluation, and has no effect > on the order in which rows are returned by the query." > The behaviour is unexpected from my perspective, but obviously there are > workarounds. Is anyone able to confirm any of this? AFAIR, others have already pointed out that without an "OR- DER BY" clause PostgreSQL can return the result set in *any* "order" it deems fit. So why don't you use one? Tim