Re: WITH x AS (...) and visibility in UPDATE - Mailing list pgsql-general

From Jack Christensen
Subject Re: WITH x AS (...) and visibility in UPDATE
Date
Msg-id 4E309AD0.2060808@hylesanderson.edu
Whole thread Raw
In response to Re: WITH x AS (...) and visibility in UPDATE  (Peter V <peterv861908@hotmail.com>)
List pgsql-general
On 7/27/2011 4:22 PM, Peter V wrote:
> I want to apply updates on a copy of a row, instead on the row itself.
> The queries are above were simplied to demonstrate the problem.
> So basically I want to do:
>
> 1) create the copy of the row and return the identifier
> 2) apply updates on the new row identified by the identifier returned in step 1
>
> If possible, I want to write this in a single command, to avoid overhead and mistakes.
>
> I tried writing a rewrite rule or before trigger, but it becomes quickly a mess to avoid infinite loops.
>
> Any ideas are welcome. Thanks.
>
Maybe I'm totally missing something, but why insert a copy and then
update instead of directly insert a mutated copy?

Something like:
INSERT INTO t (foo, bar) SELECT 'my new foo', t.bar FROM t WHERE id=123;

Wouldn't the above construction let you make a new row with some new
values and some copied values?

--
Jack Christensen
jackc@hylesanderson.edu


pgsql-general by date:

Previous
From: Peter V
Date:
Subject: Re: WITH x AS (...) and visibility in UPDATE
Next
From: Toby Corkindale
Date:
Subject: Re: repmgr problem with registering standby