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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Unable to get UPDATE ... FROM syntax correct


  • From: Gordon Ross <gr306(at)ucs(dot)cam(dot)ac(dot)uk>
  • To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
  • Subject: Unable to get UPDATE ... FROM syntax correct
  • Date: Fri, 19 Feb 2010 09:25:48 +0000
  • Message-id: <C7A4099C.4726%gr306@staff-ad.csi.cam.ac.uk> <text/plain>

I have two tables:

               Table "public.audit"
   Column   |            Type      | Modifiers
------------+----------------------+-----------
 id         | integer              | (serial)
 record_id  | integer              | not null
 key        | character varying    |
(...)


      Table "public.extension"
  Column |   Type     |  Modifiers
---------+------------+------------
 id      | integer    | (serial)
 number  | integer    |
(...)


The column "key" was recently added to the "audit" table, and I wish to
populate it with the value form the "number" column in the extension table.
The join between the tables is audit.record_id = extension.id

I tried:

UPDATE audit SET key = extension.number FROM extension WHERE audit.record_id
= extension.number;

But that returns saying "UPDATE 0"

However, doing:

SELECT audit.record_id, extension.number FROM audit, extension WHERE
audit.record_id = extension.id;

Works fine.

Can someone tell me what I'm doing wrong ?

Thanks,

GTG




Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group