[HACKERS] CTE bug?

2009-10-12 Thread David Fetter
Folks, While working to write the Sieve of Eratosthenes using CTEs, I ran across a strange error, namely that it appears I'm not allowed to nest WITH. Is this a bug? Cheers, David. WITH RECURSIVE t1(n) AS ( VALUES(2) UNION ALL SELECT n+1 FROM t1 WHERE n 1000 ), t2 (n, i) AS (

Re: [HACKERS] CTE bug?

2009-10-12 Thread Tom Lane
David Fetter da...@fetter.org writes: WITH RECURSIVE t1(n) AS ( VALUES(2) UNION ALL SELECT n+1 FROM t1 WHERE n 1000 ), t2 (n, i) AS ( SELECT 2*n+2, 2 FROM t1 WHERE 2*n+2 = 1000 UNION ALL WITH t3(k) AS ( SELECT max(i) FROM t2 ) SELECT k*n+k, k

Re: [HACKERS] CTE bug?

2009-09-09 Thread David Fetter
On Tue, Sep 08, 2009 at 11:37:14PM -0400, Tom Lane wrote: I wrote: David Fetter da...@fetter.org writes: WITH RECURSIVE t(j) AS ( WITH RECURSIVE s(i) AS ( VALUES (1) UNION ALL SELECT i+1 FROM s WHERE i 10 ) SELECT i AS j FROM s UNION ALL SELECT

Re: [HACKERS] CTE bug?

2009-09-09 Thread David Fetter
On Tue, Sep 08, 2009 at 11:37:14PM -0400, Tom Lane wrote: I wrote: David Fetter da...@fetter.org writes: WITH RECURSIVE t(j) AS ( WITH RECURSIVE s(i) AS ( VALUES (1) UNION ALL SELECT i+1 FROM s WHERE i 10 ) SELECT i AS j FROM s UNION ALL SELECT

Re: [HACKERS] CTE bug?

2009-09-09 Thread Tom Lane
David Fetter da...@fetter.org writes: Should the outer query be able to reference further-in CTEs? No, why would you expect that? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription:

Re: [HACKERS] CTE bug?

2009-09-09 Thread David Fetter
On Wed, Sep 09, 2009 at 03:00:39PM -0400, Tom Lane wrote: David Fetter da...@fetter.org writes: Should the outer query be able to reference further-in CTEs? No, why would you expect that? No particular reason, I suppose. I'm not clear on what the standard says about this. Cheers, David.

Re: [HACKERS] CTE bug?

2009-09-09 Thread Tom Lane
David Fetter da...@fetter.org writes: On Wed, Sep 09, 2009 at 03:00:39PM -0400, Tom Lane wrote: David Fetter da...@fetter.org writes: Should the outer query be able to reference further-in CTEs? No, why would you expect that? No particular reason, I suppose. I'm not clear on what the

[HACKERS] CTE bug?

2009-09-08 Thread David Fetter
Folks, I tried the following and it broke: WITH RECURSIVE t(j) AS ( WITH RECURSIVE s(i) AS ( VALUES (1) UNION ALL SELECT i+1 FROM s WHERE i 10 ) SELECT i AS j FROM s UNION ALL SELECT j+1 FROM t WHERE j 10 ) SELECT * FROM t; ERROR: relation s does not exist LINE

Re: [HACKERS] CTE bug?

2009-09-08 Thread Tom Lane
David Fetter da...@fetter.org writes: WITH RECURSIVE t(j) AS ( WITH RECURSIVE s(i) AS ( VALUES (1) UNION ALL SELECT i+1 FROM s WHERE i 10 ) SELECT i AS j FROM s UNION ALL SELECT j+1 FROM t WHERE j 10 ) SELECT * FROM t; ERROR: relation s does not exist

Re: [HACKERS] CTE bug?

2009-09-08 Thread Tom Lane
I wrote: David Fetter da...@fetter.org writes: WITH RECURSIVE t(j) AS ( WITH RECURSIVE s(i) AS ( VALUES (1) UNION ALL SELECT i+1 FROM s WHERE i 10 ) SELECT i AS j FROM s UNION ALL SELECT j+1 FROM t WHERE j 10 ) SELECT * FROM t; ERROR: relation s does