2 ms·
https://www.postgresql.org/message-id/CAM3SWZRP0c3g6+aJ=YYDGYAcTZg0xA8-1_FCVo5Xm7hrEL34kw@mail.gmail.com https://www.postgresql.org/message-id/CAM3SWZRP0c3g6+aJ
by philliphaydon 5y ago
https://www.postgresql.org/message-id/CAM3SWZRP0c3g6+aJ=YYDGYAcTZg0xA8-1_FCVo5Xm7hrEL34kw@mail.gmail.com https://www.postgresql.org/message-id/CAM3SWZRP0c3g6+aJ=YYDG...
upsert is built on top of insert while merge allows you specify multiple conditions and includes the ability to perform a delete.
i.e if you have a blog post with a list of tags, you could say:
- if submitted tag is not found > insert it
- if submitted tag is found > do nothing
- if tag exists that wasn't submitted > delete it
It can be quite powerful but it can get difficult to read also. I just hate using it in SQL Server because every time someone adds it, a year later its the code causing deadlocks.
- d_watt 5y agoThanks for the link. Now I need to dig deeper on all the concerns brought up there around non-atomicity and table level locking! Seems like it could be useful specifically for bulk uploads.