0

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?

1
  • I think this is not specific to PostgreSQL, but standard SQL Commented May 3, 2010 at 18:56

3 Answers 3

3
UPDATE new_table
SET seat = old_table.seat
FROM old_table
WHERE old_table.id = new_table.ot_id;
Sign up to request clarification or add additional context in comments.

Comments

1

IIRC the table to be updated is the one that must not be aliased. Did you try this?

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

Comments

0

You should be able to just mention seat, like so

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.