Search code examples
sqlpostgresqlbulkupdate

Bulk update in Postgres


I need to update one table records based on another one.

I tried

update      currencies
set         priority_order= t2.priority_order
from        currencies t1
inner join  currencies1 t2
on          t1.id = t2.id

but is giving error (same query work for MySQL and SQL Server).

Then I tried below:

update      currencies
set         priority_order= (select 
                            priority_order 
                            from currencies1 
                            where 
                            currencies.id=currencies1.id
                           )

It is working but is very slow, I need to do it for some big tables as well.

Any ideas?


Solution

  • In Postgres, this would look something like:

    update currencies t1
        set priority_order = t2.priority_order
        from currencies1 t2
        where t1.id = t2.id;