pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: jonathan.camile <jonathan.camile@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #8629: Strange resultset when using CTE or a subselect
Date: Tue, 26 Nov 2013 01:50:15 -0800 (PST)
Message-ID: <1385459415878-5780294.post@n5.nabble.com> (raw)
In-Reply-To: <1385408337668-5780199.post@n5.nabble.com>
References: <E1VktOG-0004bJ-16@wrigleys.postgresql.org>
	<1385408337668-5780199.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi David,

Thanks for your reply.

Here a query to create table with which I can reproduce this behavior :

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

I always have the same last result regardless of the offset or the limit I
use.
If you have any clue about what's wrong I'll be very glad.

By advance, thanks.


David Johnston wrote
> 
> jonathan.camile wrote
>> The following bug has been logged on the website:
>> 
>> Bug reference:      8629
>> Logged by:          Jonathan Camile
>> Email address:      

>> jonathan.camile@

>> 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.
> When debugging ORDER BY/LIMIT it is good practice to output the columns
> being ordered, and others if applicable, and omit the LIMIT (or makes it
> considerably larger than needed) to see what raw table data the LIMIT
> clause is seeing.  At minimum you need; "SELECT my_table.id,
> my_table.hdata->'field' FROM ..." for the output and either remove the
> limit or show at least 30 records initially.
> 
> 
> The small subset of the data you have provided is insufficient to
> determine whether you are making bad assumptions about your data or
> whether there is actually a problem.  The fact that it is not
> self-contained makes debugging difficult as well.
> 
> Note that LIMIT and OFFSET can appear in either order.  While there are
> some parts of a select statement for which the syntax dictates an order
> these do not appear to be in the group.  If they could not then LIMIT 5
> OFFSET 100 would make no sense...


David Johnston wrote
> 
> jonathan.camile wrote
>> The following bug has been logged on the website:
>> 
>> Bug reference:      8629
>> Logged by:          Jonathan Camile
>> Email address:      

>> jonathan.camile@

>> 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.
> When debugging ORDER BY/LIMIT it is good practice to output the columns
> being ordered, and others if applicable, and omit the LIMIT (or makes it
> considerably larger than needed) to see what raw table data the LIMIT
> clause is seeing.  At minimum you need; "SELECT my_table.id,
> my_table.hdata->'field' FROM ..." for the output and either remove the
> limit or show at least 30 records initially.
> 
> 
> The small subset of the data you have provided is insufficient to
> determine whether you are making bad assumptions about your data or
> whether there is actually a problem.  The fact that it is not
> self-contained makes debugging difficult as well.
> 
> Note that LIMIT and OFFSET can appear in either order.  While there are
> some parts of a select statement for which the syntax dictates an order
> these do not appear to be in the group.  If they could not then LIMIT 5
> OFFSET 100 would make no sense...


David Johnston wrote
> 
> jonathan.camile wrote
>> The following bug has been logged on the website:
>> 
>> Bug reference:      8629
>> Logged by:          Jonathan Camile
>> Email address:      

>> jonathan.camile@

>> 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.
> When debugging ORDER BY/LIMIT it is good practice to output the columns
> being ordered, and others if applicable, and omit the LIMIT (or makes it
> considerably larger than needed) to see what raw table data the LIMIT
> clause is seeing.  At minimum you need; "SELECT my_table.id,
> my_table.hdata->'field' FROM ..." for the output and either remove the
> limit or show at least 30 records initially.
> 
> 
> The small subset of the data you have provided is insufficient to
> determine whether you are making bad assumptions about your data or
> whether there is actually a problem.  The fact that it is not
> self-contained makes debugging difficult as well.
> 
> Note that LIMIT and OFFSET can appear in either order.  While there are
> some parts of a select statement for which the syntax dictates an order
> these do not appear to be in the group.  If they could not then LIMIT 5
> OFFSET 100 would make no sense...





--
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



view thread (10+ messages)  latest in thread

Message-ID: <1385459415878-5780294.post@n5.nabble.com>
Permalink:  ../1385459415878-5780294.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1385459415878-5780294.post@n5.nabble.com

 · 

reply

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: <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>

* 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