From: | Chris <dmagick(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | recursive query returning extra rows in 8.4 |
Date: | 2013-10-15 04:46:15 |
Message-ID: | 525CC897.5090006@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi all,
Using postgres 8.4.13 (latest that redhat provides in rhel6) the query
below returns an extra row compared to running the same thing in later
versions (tried 9.0, 9.1, 9.2 - they don't return the extra row).
Just wondering if anyone had thoughts on why, and/or how to remove the
duplicate row. It gets worse the more rows in the initial 'data' section.
WITH RECURSIVE data AS
(
SELECT CAST('/a/' AS TEXT) AS path, CAST(1 AS INTEGER) AS depth
UNION ALL
SELECT '/a/a/', 2
),
numbers AS
(
SELECT path, depth AS iteration, depth AS depth, 'A'
FROM data
WHERE depth =
(
SELECT MIN(depth)
FROM data
)
UNION ALL
(
WITH sub_sumbers AS
(
SELECT path, (iteration + 1) AS iteration, depth
FROM numbers
WHERE iteration <
(
SELECT MAX(depth)
FROM data
)
)
SELECT path, iteration, depth, 'b'
FROM sub_sumbers
UNION ALL
SELECT path, depth, depth, 'c'
FROM data
WHERE depth =
(
SELECT MAX(iteration)
FROM sub_sumbers
)
)
)
SELECT *
FROM numbers
ORDER BY iteration, depth;
path | iteration | depth | ?column?
-------+-----------+-------+----------
/a/ | 1 | 1 | A
/a/ | 2 | 1 | b
/a/ | 2 | 1 | b
/a/a/ | 2 | 2 | c
(4 rows)
The 'b' row is duplicated (but not in later versions of postgres).
Thanks for any suggestions/advice.
--
Postgresql & php tutorials
http://www.designmagick.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Svetlin Manavski | 2013-10-15 09:29:32 | Idle transactions in PostgreSQL 9.2.4 |
Previous Message | Huang, Suya | 2013-10-15 01:44:14 | Re: werid error"index row size 3040 exceeds btree maximum, 2712" occur randomly |