How to merge dump into database from PostgreSQL?

十年热恋 提交于 2019-12-03 06:47:55

I finally did it this way:

  1. Export to dump with:

    pg_dump -f dumpfile.sql --column-inserts -a -n <schema> -U <username> <dbname>
    
  2. Set skip unique for all tables

    CREATE OR REPLACE RULE skip_unique AS ON INSERT TO <table>
        WHERE (EXISTS (SELECT 1 FROM <table> WHERE users.id = new.id)) 
        DO INSTEAD NOTHING
    
  3. Import with psql

    \i <dumpfile.sql>
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!