Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VkzrW-0001ee-Bq for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Nov 2013 17:22:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VkzrV-0002cm-HD for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Nov 2013 17:22:17 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VktOV-0000SQ-MW for pgsql-bugs@postgresql.org; Mon, 25 Nov 2013 10:27:55 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VktOM-0006kl-7G for pgsql-bugs@postgresql.org; Mon, 25 Nov 2013 10:27:55 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VktOL-0004pM-KS for pgsql-bugs@postgresql.org; Mon, 25 Nov 2013 10:27:45 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VktOG-0004bJ-16 for pgsql-bugs@postgresql.org; Mon, 25 Nov 2013 10:27:40 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8629: Strange resultset when using CTE or a subselect To: pgsql-bugs@postgresql.org From: jonathan.camile@gmail.com Message-Id: Date: Mon, 25 Nov 2013 10:27:40 +0000 X-Pg-Spam-Score: 0.9 (/) 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 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