How to UPDATE table from csv file?

2019-08-02 14:20发布

问题:

How to update table from csv file in PostgreSQL? (version 9.2.4)

Copy command is for insert. But I need to update table. How can I update table from csv file without temp table?
I don't want to copy to temp table from csv file and update table from temp table.
And no merge command like Oracle?

回答1:

The simple and fast way is with a temporary staging table, like detailed in this closely related answer:
How to update selected rows with values from a CSV file in Postgres?

If you don't "want" that for some unknown reason, there are more ways:

  • A foreign data wrapper with file_fdw.
    You can run UPDATE commands directly using this one.

  • pg_read_file(). For special use cases.

Details in this related answer:
Read data from a text file inside a trigger

There is no MERGE command in Postgres, even less for COPY.
Discussion about whether and how to add it is ongoing. Check out the Postgres Wiki for details.