Created
June 5, 2018 04:54
-
-
Save hugomosh/426c558031e1d29ec07fb12f2a920029 to your computer and use it in GitHub Desktop.
Copy from csv to update Table PSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psql -h <dbhost> -U <user> -d <dbName> | |
CREATE TEMP TABLE tmp_x (venue_id int, address1 text); | |
CREATE TEMP TABLE tmp_x (id int, columnToUpdate text); | |
\copy tmp_x FROM '/absolute/path/to.csv' with (format csv,header true, delimiter ','); | |
UPDATE original_table | |
SET columnToUpdate = tmp_x.columnToUpdate | |
FROM tmp_x | |
WHERE original_table.id = tmp_x.id; | |
DROP TABLE tmp_x; -- else it is dropped at end of session automatically |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From : https://stackoverflow.com/questions/8910494/how-to-update-selected-rows-with-values-from-a-csv-file-in-postgres/8910810