Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VlKU3-00006Q-P4 for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Nov 2013 15:23:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VlKU3-0008JO-87 for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Nov 2013 15:23:27 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VlKU1-0008HY-Kg for pgsql-bugs@postgresql.org; Tue, 26 Nov 2013 15:23:25 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VlKTy-000423-9k for pgsql-bugs@postgresql.org; Tue, 26 Nov 2013 15:23:24 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VlKTw-0003w7-Mv for pgsql-bugs@postgresql.org; Tue, 26 Nov 2013 07:23:20 -0800 Date: Tue, 26 Nov 2013 07:23:20 -0800 (PST) From: David Johnston To: pgsql-bugs@postgresql.org Message-ID: <1385479400697-5780342.post@n5.nabble.com> In-Reply-To: <1385459415878-5780294.post@n5.nabble.com> References: <1385408337668-5780199.post@n5.nabble.com> <1385459415878-5780294.post@n5.nabble.com> Subject: Re: BUG #8629: Strange resultset when using CTE or a subselect MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 3.7 (+++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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-tp5780187p5780342.html 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