From: David Johnston <polobo@yahoo.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #8629: Strange resultset when using CTE or a subselect
Date: Tue, 26 Nov 2013 07:23:20 -0800 (PST)
Message-ID: <1385479400697-5780342.post@n5.nabble.com> (raw)
In-Reply-To: <1385459415878-5780294.post@n5.nabble.com>
References: <E1VktOG-0004bJ-16@wrigleys.postgresql.org>
<1385408337668-5780199.post@n5.nabble.com>
<1385459415878-5780294.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
jonathan.camile wrote
> CREATE TABLE public.testme AS SELECT generate_series(134800, 348008) as
> id, trunc(random() * 9 + 1) as status;
>
> Then if you play with the following query, you will reproduce it.
>
> WITH filtred_test AS (
> SELECT c.id
> FROM public.testme c
> WHERE c.status = ANY ('{5}')
> )
> SELECT mytest.id, mytest.status
> FROM public.testme mytest
> WHERE mytest.id IN (SELECT filtred_test.id FROM filtred_test)
> ORDER BY mytest.status DESC
> OFFSET 35
> LIMIT 10
Strange but not a bug - though I haven't tested it myself to prove out
anything.
You are ordering by a single field that, by definition, has the same value
for every record that the LIMIT/OFFSET sees. The ORDER BY is effectively a
no-op in this situation and the order of your output is going to be random.
Why it just happens that the same record is always in your random output I
have no clue but it is your query that is lacking here - not PostgreSQL.
You need a secondary order by field, like ID, if you want to guarantee that
different ranges provide different rows.
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-8629-Strange-resultset-when-using-CTE-or-a-subselect-tp5...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.
--
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: polobo@yahoo.com
Subject: Re: BUG #8629: Strange resultset when using CTE or a subselect
In-Reply-To: <1385479400697-5780342.post@n5.nabble.com>
References: <E1VktOG-0004bJ-16@wrigleys.postgresql.org> <1385408337668-5780199.post@n5.nabble.com> <1385459415878-5780294.post@n5.nabble.com> <1385479400697-5780342.post@n5.nabble.com>
* 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