From: jonathan.camile@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8629: Strange resultset when using CTE or a subselect
Date: Mon, 25 Nov 2013 10:27:40 +0000
Message-ID: <E1VktOG-0004bJ-16@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 8629
Logged by: Jonathan Camile
Email address: jonathan.camile@gmail.com
PostgreSQL version: 9.2.4
Operating system: Ubuntu 10.04.4 LTS
Description:
Hey folks!
I have a bit of an issue with a query and I don't understand why.
It might be not very elegant but here it is, when I use the following query
the last result will always be the same whatsoever the values of LIMIT and
OFFSET.
```
WITH filtred_table AS (
SELECT c.id
FROM my_table t
WHERE t.enabled = true
AND (t.hdata->'field')::integer = ANY ('{16788}')
)
SELECT my_table.id
FROM my_table
WHERE mycontract.id IN (SELECT filtred_table.id FROM filtred_table)
ORDER BY my_table.hdata->'field' DESC
LIMIT 5
OFFSET 0
```
Returns
```
392200574
367046368
375126026
407430954
385242163
```
```
WITH filtred_table AS (
SELECT c.id
FROM my_table t
WHERE t.enabled = true
AND (t.hdata->'field')::integer = ANY ('{16788}')
)
SELECT my_table.id
FROM my_table
WHERE mycontract.id IN (SELECT filtred_table.id FROM filtred_table)
ORDER BY my_table.hdata->'field' DESC
LIMIT 5
OFFSET 5
```
Returns
```
186939712
350754246
408507328
381550486
385242163
```
If I don't `ORDER BY` the field used to filter the issue doesn't happen.
Thanks.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: jonathan.camile@gmail.com
Subject: Re: BUG #8629: Strange resultset when using CTE or a subselect
In-Reply-To: <E1VktOG-0004bJ-16@wrigleys.postgresql.org>
References: <E1VktOG-0004bJ-16@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox