Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b4ATV-0001cK-8p for pgsql-docs@arkaria.postgresql.org; Sat, 21 May 2016 17:14:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b4ATU-0003L7-Rk for pgsql-docs@arkaria.postgresql.org; Sat, 21 May 2016 17:14:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4AT8-0002X1-88 for pgsql-docs@postgresql.org; Sat, 21 May 2016 17:13:42 +0000 Received: from mail-oi0-x234.google.com ([2607:f8b0:4003:c06::234]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b4AT5-0003LH-PD for pgsql-docs@postgresql.org; Sat, 21 May 2016 17:13:41 +0000 Received: by mail-oi0-x234.google.com with SMTP id k23so16387130oih.0 for ; Sat, 21 May 2016 10:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=Ej9DhfrGzaVCcC6jJ1FXmRArJPqCWjGnBOFmHcJIGyA=; b=T4NWfDTW/5CF2upKZWZykeBknaQzlh/OrZDNBCjphHuXgmW3d0WEOfJDghHQ0TwAsw tvihcgh8bEUhLPDBt2RdAuxSDeYkq7Kn7P8sNpDdPE70QfzXysG98ZlO68OB2EflKWoN BgCC7wq3fk8cW4FY5/mGfZVnSts2dCfBpdcrXXQt2l7281oHcBipFBEMwd9KU1bWXwX7 v6dtiA10zls1yDfBBrLvf08kBrSJ0xbUK4aIkuVAqUgvMXcl6Jcgy9/wMzBIx+Yb5DLe BKAHhRLke+QmKAsAIXy/0LaVK9FCqIrBIOxxjbYgZGSqNju/4TajXfAAJ2JYXN2dLgB/ CkBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=Ej9DhfrGzaVCcC6jJ1FXmRArJPqCWjGnBOFmHcJIGyA=; b=Uu3UAmwLxd6XN9iHnycfmTnJ1p09+6wIF9NDtWZS2RT7wJTXT+oEDQpyr1JbLLjOzw xXRbkK/EtZes+jvt5qHmEOY95Z32SOTnJyACW6BtYtGDu0UBxPXa4OqtWvFvLIY7hwVe oeIWFXdvW+leufN5qBdRkGaxaCrJmkfT7lSnBUb8t+vtoq9LkmhFQOvremwvOtt6TDt4 u8B0Qt/zz16lAB64oa98BR5I+o3QKRntcZObJtCly1nEik+4Wz4+/geGTJ+EtjRoKjuv baLNfy/E1sWgjURrOE/83eYOvN3+EhWwho91bY29GSXaeWP14qLS3xldVpLAXMLgQcwo 90AQ== X-Gm-Message-State: AOPr4FW+PlDnG7jUBbwj/jlRZp6MKoHLMG2Oyl8bc71YqJe+wncYLsVq5crBXrxqOOZ2T+cLvUG+YigETVS8MA== MIME-Version: 1.0 X-Received: by 10.157.2.74 with SMTP id 68mr4541637otb.155.1463850818530; Sat, 21 May 2016 10:13:38 -0700 (PDT) Received: by 10.157.37.93 with HTTP; Sat, 21 May 2016 10:13:38 -0700 (PDT) In-Reply-To: <55820.1463850163@sss.pgh.pa.us> References: <55062.1463778448@sss.pgh.pa.us> <55820.1463850163@sss.pgh.pa.us> Date: Sat, 21 May 2016 13:13:38 -0400 Message-ID: Subject: Re: Is this example regarding aggregates sourced by subquery correct? From: "David G. Johnston" To: Tom Lane Cc: "pgsql-docs@postgresql.org" Content-Type: multipart/alternative; boundary=94eb2c114d1e0afbc905335d5481 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org --94eb2c114d1e0afbc905335d5481 Content-Type: text/plain; charset=UTF-8 On Saturday, May 21, 2016, Tom Lane wrote: > "David G. Johnston" > writes: > > Based upon what you've said I would soften it a bit. Given my own > > experience I'd probably point out what is now obvious to me - that the > > allowance of the ORDER BY clause is implementation specific. But I'd be > > fine chalking that up to an anomalous reading. > > > Something like: > > > "But permitting the sub-query's ORDER BY was only upgraded to optional in > > SQL:2008 and thus this syntax poses a portability hazard." > > After further thought I realized that this gripe applies just as much > to the alternative we're comparing this to, ie, putting ORDER BY into > the aggregate call. (I've not looked up whether the two features were > introduced in exactly the same SQL version, but I am pretty sure they > are both post-SQL99.) So we might as well just take it out. What we > could usefully do instead is explain exactly what's dangerous about > using a subquery ORDER BY in this way. So I changed it to > > Beware that this approach can fail if the outer query level contains > additional processing, such as a join, because that might cause the > subquery's output to be reordered before the aggregate is computed. > > That works. There's only so much portability warning that is useful and we should focus on better informing how postgreSQL functions. Thanks. David J. --94eb2c114d1e0afbc905335d5481 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Saturday, May 21, 2016, Tom Lane <tgl@sss.pgh.pa.us> wrote:
david.g.johns= ton@gmail.com> writes:
> Based upon what you've said I would soften it a bit.=C2=A0 Given m= y own
> experience I'd probably point out what is now obvious to me - that= the
> allowance of the ORDER BY clause is implementation specific.=C2=A0 But= I'd be
> fine chalking that up to an anomalous reading.

> Something like:

> "But permitting the sub-query's ORDER BY was only upgraded to= optional in
> SQL:2008 and thus this syntax poses a portability hazard."

After further thought I realized that this gripe applies just as much
to the alternative we're comparing this to, ie, putting ORDER BY into the aggregate call.=C2=A0 (I've not looked up whether the two features = were
introduced in exactly the same SQL version, but I am pretty sure they
are both post-SQL99.)=C2=A0 So we might as well just take it out.=C2=A0 Wha= t we
could usefully do instead is explain exactly what's dangerous about
using a subquery ORDER BY in this way.=C2=A0 So I changed it to

=C2=A0 =C2=A0Beware that this approach can fail if the outer query level co= ntains
=C2=A0 =C2=A0additional processing, such as a join, because that might caus= e the
=C2=A0 =C2=A0subquery's output to be reordered before the aggregate is = computed.


That works.=C2=A0 There's only so much= portability warning that is useful and we should focus on better informing= how postgreSQL functions.

Thanks.

David = J. --94eb2c114d1e0afbc905335d5481--