Created
July 4, 2020 19:41
-
-
Save sergiandreplace/93bf0f5f01570c6e5f28b3bb5352afc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
drop table if exists medicines_import; | |
CREATE TABLE medicines_import ( | |
country text NOT NULL, | |
code text NOT NULL, | |
name text NOT NULL, | |
quantity int4 NOT NULL, | |
unit text NOT NULL, | |
CONSTRAINT medicines_pkey PRIMARY KEY (code, country) | |
); | |
copy medicines_import (country, code, name, quantity, unit) from '/Users/sergi.martinez/dev/newmeds.csv' DELIMITER ',' csv header; | |
insert into medicines(country, code, name, quantity, unit) | |
(select country, code, name, quantity, unit from medicines_import) | |
ON CONFLICT (country, code) DO UPDATE | |
SET name = excluded.name, quantity = excluded.quantity, unit = excluded.unit; | |
select * from medicines m order by code; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment