Re: wCTE behaviour - Mailing list pgsql-hackers

From Yeb Havinga
Subject Re: wCTE behaviour
Date
Msg-id 4CDE9283.3000304@gmail.com
Whole thread Raw
In response to Re: wCTE behaviour  (David Fetter <david@fetter.org>)
Responses Re: wCTE behaviour
List pgsql-hackers
On 2010-11-12 16:51, David Fetter wrote:
> On Fri, Nov 12, 2010 at 10:25:51AM -0500, Tom Lane wrote:
>>
>> Yeah, that's another interesting question: should we somehow force
>> unreferenced CTEs to be evaluated anyhow?
> Yes.
After a night's sleep I'm still thinking no. Arguments:
1) the name "Common Table Expression" suggests that t must be regarded 
as an expression, hence syntactically / proof theoretic and not as a 
table, set of rows / model theoretic. I.e. it is not a "Common Table".
2) The expressions can be referenced zero, one or more times. To me it 
therefore makes the most sense that a DML expressions that is defined 
but not references has no effect. Referenced once: run the plan once. 
Referenced again: run the plan again.

What should the result be of
WITH t AS (INSERT INTO foo SELECT nextval('seq') RETURNING *)
SELECT * FROM t
UNION
SELECT * FROM t;

1 or 1,2 ?

regards,
Yeb Havinga



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: max_wal_senders must die
Next
From: Magnus Hagander
Date:
Subject: Re: duplicate connection failure messages