Re: xmlagg doesn't honor LIMIT?

From: Peter Kroon <plakroon(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: xmlagg doesn't honor LIMIT?
Date: 2013-11-26 13:39:46
Message-ID: CAOh+DOmGNX-rt5ePSa4_+2Px7YUwg6FR_KfOmk9w7uEbr2DSvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This is how I solved it:

SELECT
xmlagg(
xmlconcat(
xmlelement(name test_element,
xmlforest(
ff.d AS a
)--xmlforest
)
)--xmlconcat
)--xmlagg

FROM (
SELECT
--xmlagg(
xmlconcat(
xmlelement(name test_element,
xmlattributes(
0 AS m
),
xmlforest(
dh.id AS i
,dh.some_value AS sv
)--xmlforest
)--test_element
) AS d
--)
FROM __pg_test_table AS dh
WHERE dh.__rel=5 LIMIT 2 --OFFSET 10;
) AS ff;

2013/11/26 Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>

> Peter Kroon wrote:
> > Is anyone able to reproduce?
> > When I run the query below all 5 rows are returned instead of 2.
> > Or is this the default behaviour..
>
> > SELECT
> > xmlagg(
> [...]
> > )--xmlagg
> > FROM __pg_test_table AS dh
> > WHERE dh.__rel=5 LIMIT 2 --OFFSET 10;
>
> According to the documentation, that query should return
> exactly one row since xmlagg is an aggregate.
>
> So the LIMIT 2 won't do anything to the result.
>
> You can wrap your query in a
> SELECT count(*) FROM (SELECT ...) AS dummy;
> to see how many rows you got.
>
> Yours,
> Laurenz Albe
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Chris Curvey 2013-11-26 14:25:17 restore crashes PG on Linux, works on Windows
Previous Message Nelson Green 2013-11-26 13:26:22 Re: Inserting rows containing composite foreign keys