开发者

SQL import file to update table values

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
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜