pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: luisa.j.francisco@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #7790: null filters in CTEs don't work
Date: Sun, 06 Jan 2013 04:58:07 +0000
Message-ID: <E1TriJD-0005aH-KR@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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:        

Expected output should have no nulls in it, but it does:

--------
CREATE TABLE item_tree(
    id		text PRIMARY KEY, 
    parent_id	text
);

INSERT INTO item_tree (id, parent_id) VALUES
	('body', null), 
	('head', 'body'), 
	('mouth', 'head'), 
	('eye', 'head'), 
	('tooth', 'mouth'), 
	('tongue', 'mouth'), 
	('sclera', 'eye'), 
	('cornea', 'eye')
;

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 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 ( 
  SELECT id, parent_id 
  FROM item_tree i
  UNION ALL
  SELECT t.id, i.parent_id 
  FROM item_tree i 
  JOIN t 
  ON i.id = t.parent_id 
)
SELECT * FROM t ORDER BY id;
) t1 WHERE parent_id IS NOT NULL
------------



-- 
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 (2+ messages)  latest in thread

Message-ID: <E1TriJD-0005aH-KR@wrigleys.postgresql.org>
Permalink:  ../E1TriJD-0005aH-KR@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1TriJD-0005aH-KR@wrigleys.postgresql.org

 · 

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: luisa.j.francisco@gmail.com
  Subject: Re: BUG #7790: null filters in CTEs don't work
  In-Reply-To: <E1TriJD-0005aH-KR@wrigleys.postgresql.org>
  References: <E1TriJD-0005aH-KR@wrigleys.postgresql.org>

* 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