Skip to content

Instantly share code, notes, and snippets.

@hugomosh
Created June 5, 2018 04:54
Show Gist options
  • Save hugomosh/426c558031e1d29ec07fb12f2a920029 to your computer and use it in GitHub Desktop.
Save hugomosh/426c558031e1d29ec07fb12f2a920029 to your computer and use it in GitHub Desktop.
Copy from csv to update Table PSQL
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