Skip site navigation (1) Skip section navigation (2)

Re: update a table from a temp table

From: Thom Brown <thom(at)linux(dot)com>
To: Charles Holleran <scorpdaddy(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: update a table from a temp table
Date: 2010-08-17 18:20:58
Message-ID: AANLkTin=Hoxow4Ebd5h1ieTv4=reSUcMz9A-JUCroxwE@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 17 August 2010 19:09, Charles Holleran <scorpdaddy(at)hotmail(dot)com> wrote:
> Referring to the syntax for updating a table from a temp table at "Update a
> field in a table using a value from another table ..." at
> http://www.cryer.co.uk/brian/sql/sql_crib_sheet.htm
>
> Is this the correct syntax for PG for updating a table from a temp table?
>

No, you need to use a FROM clause if you wish to update based on another table.

Taking the example from that page you linked to:

UPDATE tableone
SET field1 = tabletwo.fieldx
FROM tabletwo
WHERE tableone.commonid = tabletwo.commonid;

Look at http://www.postgresql.org/docs/current/static/sql-update.html
for more information.

Regards
-- 
Thom Brown
Registered Linux user: #516935

In response to

pgsql-novice by date

Next:From: Charles Holleran Date: 2010-08-17 19:41:20
Subject: Re: update a table from a temp table
Previous:From: Charles HolleranDate: 2010-08-17 18:09:44
Subject: update a table from a temp table

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group