I have many, many between foo and bar , modeled as a table foo_bar with foo_id and bar_id .
Now I would like to simulate this as one-to-many (which my data allows).
I added the foo_id column to bar , but now I want to transfer my data. So i want
UPDATE bar SET foo_id = f where id = b;
where each pair f and b comes from
SELECT foo_id AS f, bar_id AS b FROM foo_bar;
Is it possible to do this in SQL (and in particular PostgreSQL 9.0)?
I know how to do sub-SELECT in UPDATE when there is only one value, but to a dead end how to do it in this case.
source share