Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3qjA-0004Et-7p for pgsql-docs@arkaria.postgresql.org; Fri, 20 May 2016 20:08:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b3qj9-0004QB-3k for pgsql-docs@arkaria.postgresql.org; Fri, 20 May 2016 20:08:55 +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 1b3qin-00041o-05 for pgsql-docs@postgresql.org; Fri, 20 May 2016 20:08:33 +0000 Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b3qij-0005WY-CP for pgsql-docs@postgresql.org; Fri, 20 May 2016 20:08:32 +0000 Received: by mail-oi0-x231.google.com with SMTP id v145so195822196oie.0 for ; Fri, 20 May 2016 13:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=suY52RYAj/kuimbeE/1ksU+rDjUcET3wPOKs06lAxBU=; b=SSY+JU7ZNhMu/Lgl4Vq2SmeJ8ntwBzJBL+NIb/4Caj6k+LEyNWixoZQbKhH1R25F+2 Tv+GvKbMv8pvC7FEGWcOw1lM7WENahRnPsvXz6i1D0sVPZpf4Pyki9SIeUX0XuBAgThy 3J6PX93TMgyjK9t7fx3d5sA/GUG7T5d7VJPpZYS05KU5hWcQ+udEmOPtAwqQ4+aQyEGX uNbDDrs6w0m7O6KaO47aApnsvx+xLN9XvziG/qLBZPVKzwPXxIgnrfw4dS3NLAHIk2DR hdpxVjMv1S8JLxjlQ6wFhTg07+LHu6gvE3abEPT2xPt3cavhXAmG0lFLTisU1GQL7wzp 4U4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=suY52RYAj/kuimbeE/1ksU+rDjUcET3wPOKs06lAxBU=; b=DC7eOm0X+ct1Ogc5T0mpmBKfcpxR/UswJeqMFlQ3RRmtmd7lY2zbJuHKx0mKaJNHIi L4Ru/+FzsP69/jU7qXI3Hc8FmU1W1Vh/zYWVsQ9GbtWBIhUaaC3l+5b4g0w+63d19oJY 30AfxMZEZ+1POrhdfzWdemboeMlB/PJHgoIaPsoauSeV0HUQgPNVoi1rQMAZE7kXvelA TxYlpwEXoKCreylWpCcjUQYf4WOSga5KhBUYHJbn5Wg281ryw9ywEtaO1F9wEksjinPn ZDVzIKVOdHRUN6BRa0WSC8hzsM4OC5S42DGbT+Sg4jEcpYgctr9EHdmyykwMimZRA6IE dSFg== X-Gm-Message-State: AOPr4FU4QtsBKen0ftYGt38UHxEKLKTH6v4O69gyAOfqwnQKnJh4ieKfMPcikL2K+cvAvyLIE5vhu+Pmdx3OCA== MIME-Version: 1.0 X-Received: by 10.202.96.68 with SMTP id u65mr2859400oib.83.1463774907427; Fri, 20 May 2016 13:08:27 -0700 (PDT) Received: by 10.157.37.93 with HTTP; Fri, 20 May 2016 13:08:27 -0700 (PDT) Date: Fri, 20 May 2016 16:08:27 -0400 Message-ID: Subject: Is this example regarding aggregates sourced by subquery correct? From: "David G. Johnston" To: "pgsql-docs@postgresql.org" Content-Type: multipart/alternative; boundary=001a113d5d26637f2a05334ba7f9 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 --001a113d5d26637f2a05334ba7f9 Content-Type: text/plain; charset=UTF-8 http://www.postgresql.org/docs/9.5/static/functions-aggregate.html """ ...This ordering is unspecified by default, but can be controlled by writing an ORDER BY clause within the aggregate call, as shown in Section 4.2.7. Alternatively, supplying the input values from a sorted subquery will usually work. For example: SELECT xmlagg(x) FROM (SELECT x FROM test ORDER BY y DESC) AS tab; But this syntax is not allowed in the SQL standard, and is not portable to other database systems. """ This seems incorrect - I was expecting something like: SELECT xmlagg((SELECT x FROM test ORDER BY y DESC)) The example seems expressly permitted by the standard and other database systems. I'll believe that said ordering in the example is not guaranteed but that isn't what it says. David J. --001a113d5d26637f2a05334ba7f9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

...This ordering is unspecified b= y default, but can be controlled by writing an ORDER BY clause within the a= ggregate call, as shown in Section 4.2.7. Alternatively, supplying the inpu= t values from a sorted subquery will usually work. For example:

SELECT xmlagg(x) FROM (SELECT x FROM te= st ORDER BY y DESC) AS tab;

But this syntax is not allowed in the SQL standard, and is not portable= to other database systems.
"""

= This seems incorrect - I was ex= pecting something like:

SELE= CT xmlagg((SELECT x FROM test ORDER BY y DESC))

The example seems expressly permitted by the standard a= nd other database systems.

I'll believe that said ordering in the example is not guaranteed but t= hat isn't what it says.

David J.

--001a113d5d26637f2a05334ba7f9--