To ignore duplicate keys during 'copy from' in postgresql

前端 未结 4 883
天命终不由人
天命终不由人 2020-12-07 14:11

I have to dump large amount of data from file to a table PostgreSQL. I know it does not support \'Ignore\' \'replace\' etc as done in MySql. Almost all posts regarding this

4条回答
  •  半阙折子戏
    2020-12-07 14:16

    PostgreSQL 9.5 now has upsert functionality. You can follow Igor's instructions, except that final INSERT includes the clause ON CONFLICT DO NOTHING.

    INSERT INTO main_table
    SELECT *
    FROM tmp_table
    ON CONFLICT DO NOTHING
    

提交回复
热议问题