I'm using PostgreSQL and have a table, named table_all
, with 5 million lines and this structure:
id|source_id|destination_id|some_flag
1 | 12 | 13 | NULL
2 | 12 | 14 | NULL
...
And another table table_flag
with the same number of rows and the following structure:
id|some_flag
1 | true
2 | false
...
I need to set some_flag
in table_all
with the values from table_flag
. If I issue a statement like:
UPDATE table_all set some_flag = table_flag.some_flag
from table_flag
where table_all.id = table_flag.id
it takes hours, and I need to perform this operation quite often. The two tables are ordered by id, which is unique, and both tables have all ids. Intuitively for me, setting some_flag
in table_all
with the values from table_flag
is only a matter of performing a bulk copy from table_flag
to table_all
. Is there a way to do this?