Updating records in Postgres using FROM clause

Posted by Summer on Stack Overflow See other posts from Stack Overflow or by Summer
Published on 2010-05-03T18:46:14Z Indexed on 2010/05/03 18:58 UTC
Read the original article Hit count: 281

Filed under:
|

Hi,

I'm changing my db schema, and moving column 'seat' from old_table to new_table. First I added a 'seat' column to new_table. Now I'm trying to populate the column with the values from old_table.

UPDATE new_table
SET seat = seat
FROM old_table
WHERE old_table.id = new_table.ot_id;

This returns ERROR: column reference "seat" is ambiguous.

UPDATE new_table nt
SET nt.seat = ot.seat
FROM old_table ot
WHERE ot.id = nt.ot_id;

Returns ERROR: column "nt" of relation "new_table" does not exist

Ideas?

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about sql