how to emulate “insert ignore” and “on duplicate key update” (sql merge) with postgresql?
Some SQL servers have a feature where INSERT is skipped if it would violate a primary/unique key constraint. For instance, MySQL has INSERT IGNORE . What's the best way to emulate INSERT IGNORE and ON DUPLICATE KEY UPDATE with PostgreSQL? Magnus Hagander Try to do an UPDATE. If it doesn't modify any row that means it didn't exist, so do an insert. Obviously, you do this inside a transaction. You can of course wrap this in a function if you don't want to put the extra code on the client side. You also need a loop for the very rare race condition in that thinking. There's an example of this in