Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Thu, Oct 10, 2013 at 10:03 AM, Rob Richardson
> <RDRichardson@xxxxxxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux