Re: Writeable CTEs and side effects

From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Writeable CTEs and side effects
Date: 2009-10-19 14:29:45
Message-ID: 4ADC77D9.5070303@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
>> Is the above form:
>> with x as (delete .. returning *) insert into y select * from x
>> going to be allowed? I was informed on irc that it wasn't...it would
>> have to be written as:
>> insert into y with x as (delete .. returning *) select * from x
>
> I would think that we would require the former and forbid the latter.
> One of the basic limitations of the feature is going to be that you
> can only have WITH (something RETURNING) at the top level, and the
> latter syntax doesn't look like that to me.

I'm looking at this, and if I understood correctly, you're suggesting
we'd add a WithClause to InsertStmt. Would we also allow this?

WITH t1 AS (DELETE FROM foo RETURNING *)
INSERT INTO bar
WITH t2 AS (VALUES(0))
SELECT * FROM t1 UNION ALL
SELECT * FROM t2;

I could also see use for adding this for UDPATE and DELETE too, i.e.

WITH t AS (DELETE FROM foo RETURNING id)
UPDATE bar SET foo_id = NULL FROM t WHERE t.id = bar.foo_id;

Did I misunderstand something here?

Regards,
Marko Tiikkaja

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-10-19 14:30:05 Re: Rejecting weak passwords
Previous Message David Fetter 2009-10-19 14:17:00 Re: Application name patch - v2