From: Tom Lane <tgl@sss.pgh.pa.us>
To: luisa.j.francisco@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7790: null filters in CTEs don't work
Date: Sun, 06 Jan 2013 20:13:01 -0500
Message-ID: <10864.1357521181@sss.pgh.pa.us> (raw)
In-Reply-To: <E1TriJD-0005aH-KR@wrigleys.postgresql.org>
References: <E1TriJD-0005aH-KR@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
luisa.j.francisco@gmail.com writes:
> Expected output should have no nulls in it, but it does:
It's not apparent to me why you think the first query shouldn't produce
any rows with null parent_id? AFAICS, the recursive query will "crawl
up the tree" producing a row for every parent level above the given
base-case rows. Eventually you'll get up to a match to the row
('body', null), and there's nothing to stop that from being displayed.
It's a bit easier to see what's happening if you leave off the "ORDER
BY" so that the rows are printed in generation order:
regression=# SELECT id, parent_id
FROM item_tree i
WHERE parent_id IS NOT NULL
AND id NOT IN (
SELECT parent_id
FROM item_tree
WHERE parent_id IS NOT NULL);
id | parent_id
--------+-----------
tooth | mouth
tongue | mouth
sclera | eye
cornea | eye
(4 rows)
regression=# WITH RECURSIVE t(id, parent_id) AS (
SELECT id, parent_id
FROM item_tree i
WHERE parent_id IS NOT NULL
AND id NOT IN (
SELECT parent_id
FROM item_tree
WHERE parent_id IS NOT NULL)
UNION ALL
SELECT t.id, i.parent_id
FROM item_tree i
JOIN t
ON i.id = t.parent_id
)
SELECT * FROM t;
id | parent_id
--------+-----------
tooth | mouth
tongue | mouth
sclera | eye
cornea | eye
tooth | head
tongue | head
sclera | head
cornea | head
tooth | body
tongue | body
sclera | body
cornea | body
tooth |
tongue |
sclera |
cornea |
(16 rows)
regards, tom lane
--
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: tgl@sss.pgh.pa.us, luisa.j.francisco@gmail.com
Subject: Re: BUG #7790: null filters in CTEs don't work
In-Reply-To: <10864.1357521181@sss.pgh.pa.us>
References: <E1TriJD-0005aH-KR@wrigleys.postgresql.org> <10864.1357521181@sss.pgh.pa.us>
* 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