1

I want to update a table with postgresql.

In fact, I have a table (TABLE_ONE) with two column (old_id and new_id). I have a second table (TABLE_TWO) with colums (id,column1,column2,...).

I want to update the column id from TABLE_TWO. The wanted behavior is that when TABLE_ONE.id = TABLE_TWO.old_id, we set id to new_id.

How can i do that?

1 Answer 1

2

You want an UPDATE FROM statement:

UPDATE table_one
SET table_one.id = table_two.id
FROM table_two
WHERE table_one.id = table_two.old_id;
Sign up to request clarification or add additional context in comments.

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.