5 ms·
i've seen a system in mysql do "insert on duplicate key update" for ages, so this is that same pattern?
by ryan0x00 11y ago
i've seen a system in mysql do "insert on duplicate key update" for ages, so this is that same pattern?
- girvo 11y agoYeah, it is the same as INSERT ... ON DUPLICATE KEY UPDATE, and similar to REPLACE in MySQL. Exciting to see it in Postgres!
- kkland 11y agoI think the way MySQL works in doing "INSERT ... ON DUPLICATE KEY UPDATE" is to delete the old row and insert a new row if there's an auto incremental column (mostly it's ID column). Being curious if Postgres works the same way in this regard.
- dugmartin 11y agoNo, the auto increment columns are maintained as is.
- kkland 11y agoThat's great. Otherwise, it just wastes IDs unless one figures out a workaround for it.
- girvo 11y agoNo, that's how REPLACE works -- which is a complete pain to be honest! INSERT ... UPDATE works the way you'd hope it would, and keeps the auto inc columns correct.