Re: Why doesn't update syntax match insert syntax?

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>, Rob Richardson <RDRichardson(at)rad-con(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why doesn't update syntax match insert syntax?
Date: 2013-10-10 18:25:56
Message-ID: B6F6FD62F2624C4C9916AC0175D56D880CE2A703@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Thu, Oct 10, 2013 at 10:03 AM, Rob Richardson
> <RDRichardson(at)rad-con(dot)com> wrote:
>
> > UPDATE inner_covers
> > SET X = (SELECT sl.X FROM storage_locations sl where sl.name = inner_covers.name),
> > Y = (SELECT sl.Y FROM storage_locations sl where sl.name = inner_covers.name)
> >
> > Or is there another, more convenient form of the UPDATE query that I'm not familiar with?
> >
> > Thanks very much!
>
> you have UPDATE FROM:
>
> UPDATE foo SET a=bar.a, b=bar.b
> FROM bar WHERE foo.id = bar.id;
>
> merlin

Hi,

an alternate syntax which is nearer to the INSERT one:

update foo set (a,b) = (bar.a, bar.b)
FROM bar
WHERE foo.id = bar.id;

I guess this is just a question of taste...

regards,

Marc Mamin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adam Mackler 2013-10-10 20:06:11 Re: Can a view represent a schedule for all days into the future?
Previous Message David Johnston 2013-10-10 17:42:47 Re: Can a view represent a schedule for all days into the future?