Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Trx10-00073d-Fe for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Jan 2013 20:40:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Trx0z-00072B-Je for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Jan 2013 20:40:17 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TriJH-00054I-LK for pgsql-bugs@postgresql.org; Sun, 06 Jan 2013 04:58:11 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TriJF-0006w2-3D for pgsql-bugs@postgresql.org; Sun, 06 Jan 2013 04:58:10 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TriJE-000863-Be for pgsql-bugs@postgresql.org; Sun, 06 Jan 2013 04:58:08 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1TriJD-0005aH-KR for pgsql-bugs@postgresql.org; Sun, 06 Jan 2013 04:58:07 +0000 Date: Sun, 06 Jan 2013 04:58:07 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7790: null filters in CTEs don't work To: pgsql-bugs@postgresql.org From: luisa.j.francisco@gmail.com X-Pg-Spam-Score: -1.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: 7790 Logged by: Luisa Francisco Email address: luisa.j.francisco@gmail.com PostgreSQL version: 9.2.2 Operating system: 32-bit Windows 7 SP1 Description:=20=20=20=20=20=20=20=20 Expected output should have no nulls in it, but it does: -------- CREATE TABLE item_tree( id text PRIMARY KEY,=20 parent_id text ); INSERT INTO item_tree (id, parent_id) VALUES ('body', null),=20 ('head', 'body'),=20 ('mouth', 'head'),=20 ('eye', 'head'),=20 ('tooth', 'mouth'),=20 ('tongue', 'mouth'),=20 ('sclera', 'eye'),=20 ('cornea', 'eye') ; WITH RECURSIVE t(id, parent_id) AS (=20 SELECT id, parent_id=20 FROM item_tree i WHERE parent_id IS NOT NULL AND id NOT IN ( SELECT parent_id=20 FROM item_tree=20 WHERE parent_id IS NOT NULL) UNION ALL SELECT t.id, i.parent_id=20 FROM item_tree i=20 JOIN t=20 ON i.id =3D t.parent_id=20 ) SELECT * FROM t ORDER BY id; ----------- Output is as follows: id parent_id ------ --------- cornea eye cornea NULL cornea head cornea body sclera eye sclera head sclera NULL sclera body tongue body tongue head tongue NULL tongue mouth tooth body tooth head tooth mouth tooth NULL However, enclosing the query with a outer select-null-filter works even if all the inner filters were deleted as below: --------- SELECT * FROM ( WITH RECURSIVE t(id, parent_id) AS (=20 SELECT id, parent_id=20 FROM item_tree i UNION ALL SELECT t.id, i.parent_id=20 FROM item_tree i=20 JOIN t=20 ON i.id =3D t.parent_id=20 ) SELECT * FROM t ORDER BY id; ) t1 WHERE parent_id IS NOT NULL ------------ --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs