How to UPDATE table from csv file?

余生长醉 提交于 2020-01-05 10:33:19

问题


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.



来源:https://stackoverflow.com/questions/19973102/how-to-update-table-from-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!