Re: Expanding DELETE/UPDATE returning

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: David Fetter <david(at)fetter(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rusty Conover <rconover(at)infogears(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Expanding DELETE/UPDATE returning
Date: 2007-02-27 14:07:06
Message-ID: 45E43B0A.1050501@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David Fetter wrote:
> On Mon, Feb 26, 2007 at 11:14:01PM -0500, Tom Lane wrote:
>> Rusty Conover <rconover(at)infogears(dot)com> writes:
>>> Or allow delete and update to be used in sub-queries?
>> That's been discussed but the implementation effort seems far from
>> trivial. One big problem is that a sub-query can normally be
>> re-executed multiple times, eg on the inner side of a join; whereas
>> that's clearly not acceptable for an insert/update/delete.
>
> What kinds of machinery would be needed in order for certain kinds of
> subqueries to get executed only once and have the results cached?
>
> <brain_storm>
>
> INSERT/UPDATE/DELETE ... RETURNING wouldn't be the only possible uses
> of such machinery. A data-changing function in a subquery could be
> another. Maybe there could be some way to mark functions as "execute
> once per subquery."

Is "execute only once" even well-defined for subqueries? Take for example

select * from t1, (delete from t2 returning t2.t1_id) where t1.id =
t2.t1_id ;

Will this delete all record from t2, or just those records for which
a matching record in t1 exists? In case you vote for "all records"
above, now take

select * from t1, (delete from t2 returning t2.t1_id) where t1.id =
t2.t1_id limit 1 ;

I for my part couldn't even say what I'd expect that query to do.
Do other databases support this?

greetings, Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Florian G. Pflug 2007-02-27 14:11:05 Re: Proposal for Implenting read-only queries during wal replay (SoC 2007)
Previous Message Andrew Dunstan 2007-02-27 14:01:28 Re: Developer TODO List as a PostgreSQL DB