Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b4AIx-00013C-Fs for pgsql-docs@arkaria.postgresql.org; Sat, 21 May 2016 17:03:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b4AIx-0001PP-25 for pgsql-docs@arkaria.postgresql.org; Sat, 21 May 2016 17:03:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4AIb-0000cL-2v for pgsql-docs@postgresql.org; Sat, 21 May 2016 17:02:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b4AIY-0008WS-5Q for pgsql-docs@postgresql.org; Sat, 21 May 2016 17:02:48 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u4LH2hdD018447; Sat, 21 May 2016 13:02:43 -0400 From: Tom Lane To: "David G. Johnston" cc: "pgsql-docs@postgresql.org" Subject: Re: Is this example regarding aggregates sourced by subquery correct? In-reply-to: References: <55062.1463778448@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Fri, 20 May 2016 18:41:33 -0400" Date: Sat, 21 May 2016 13:02:43 -0400 Message-ID: <55820.1463850163@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) 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 "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. regards, tom lane -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs