Created
July 6, 2022 06:49
-
-
Save ValentinMouret/71287ca5eb2cc150c11213a39d32289a 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
cat /Users/valentinmouret/Desktop/users.csv \ | |
| psql -c " | |
begin; | |
create temp table batch_user ( | |
id text primary key, | |
document jsonb not null | |
); | |
copy batch_user (id, document) | |
-- We can run the same command but reading from standard input | |
-- intead of a file on the file system. | |
from STDIN | |
with (format 'csv', | |
header, | |
delimiter ','); | |
insert into user | |
(id, email) | |
select batch_user.id, | |
batch_user.document->>'email' as email | |
from batch_user | |
left join user | |
using (id) | |
where user.id is null | |
and batch_user.document->>'email' is not null; | |
commit;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment