Re: WITH x AS (...) and visibility in UPDATE

From: Jack Christensen <jackc(at)hylesanderson(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: WITH x AS (...) and visibility in UPDATE
Date: 2011-07-27 23:10:08
Message-ID: 4E309AD0.2060808@hylesanderson.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)hylesanderson(dot)edu

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Toby Corkindale 2011-07-28 00:24:52 Re: repmgr problem with registering standby
Previous Message Peter V 2011-07-27 21:22:08 Re: WITH x AS (...) and visibility in UPDATE