Skip to content

Instantly share code, notes, and snippets.

@sergiandreplace
Created July 4, 2020 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiandreplace/93bf0f5f01570c6e5f28b3bb5352afc0 to your computer and use it in GitHub Desktop.
Save sergiandreplace/93bf0f5f01570c6e5f28b3bb5352afc0 to your computer and use it in GitHub Desktop.
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