How do I 开发者_运维技巧import an csv file to a database either SQLite or Postgresql so that it updates values already in the table and of course also inserts new ones.
Thank you...
PD: Im loving this community. Fast Accurate answers.
I'm not familiar enough with sqlite to know if the same constructs are available, but you also asked about Postgres. So... with Postgres, I would use the COPY FROM command to import the data to a staging table. Then I would run the following SQL:
UPDATE destination d
SET [whatever you are updating]
FROM staging s
WHERE d.id = s.id
INSERT INTO destination
SELECT * FROM staging s
WHERE s.id NOT IN (
SELECT id FROM destination
)
精彩评论