英文:
Update or insert in PostgreSQL database
问题
我正在将Firebird数据库迁移到PostgreSQL数据库。我在Firebird数据库中使用了update or insert方法。我发现在PostgreSQL数据库中可以使用on conflict方法。问题是,要使用on conflict,表列必须具有唯一约束,否则它将无法工作。在我的情况下,我无法在表中使用唯一约束。如何在PostgreSQL数据库中实现更新或插入方法?
英文:
I am migrating a Firebird database to a PostgreSQL database. I have used update or insert method in the Firebird database. I have found we can use on conflict method in PostgreSQL database. The problem is, in order to use on conflict, the table column must have a unique constraint otherwise it won't work. In my case, I can't use unique constraints in my table.
How can I implement an update or insert method in the PostgreSQL database.
答案1
得分: 0
你可以使用 MERGE 语句,就像在Firebird中使用它作为 UPDATE OR INSERT 的替代方式。
英文:
You can use the MERGE statement, just like you can use in Firebird as an alternative to UPDATE OR INSERT.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论