Prompt how it would be correct to create one request in which the data in several tables would be updated at once? In MySQL, I used this method before.

UPDATE customer, customer_order SET closed = 1, closedAt = NOW() WHERE closed = 0 AND accept = 1; 

But PostgreSQL shows an error

 ERROR: syntax error at or near "," LINE 1: UPDATE customer, customer_order ^ 

I do not really want to do separate requests. Maybe there is an option to do everything in one?

    2 answers 2

    No, no. One UPDATE can update only one table. Specifying multiple tables is a syntax error.

    In order for this to be applied atomically to the database, you need to make two separate UPDATE in one transaction.

    The situation is somewhat different for updating one table based on values ​​in another, filtered by joining ( JOIN ), for example. There you can specify a join table in FROM and specify join conditions in WHERE .


    UPDATE documentation.

      A universal way to do anything with one request is to use CTE , writing requests are fully supported.

       with write_customer as ( update customers set /**/ where /**/ ) update customer_order set /**/ where /**/ 

      By your example, I do not understand what and where should have been updated in mysql , the tables are not related to each other and it is not clear which fields are related to which table. If you only need to write one table, but on the basis of the data of the other, you can do it with a simple update .