Top all-time · #19430
Michael J. Swart
Personal blog · michaeljswart.comdataprogramming
Michael J. Swart's personal blog at michaeljswart.com covers data and programming. Since 2020, 4 different Hacker News readers have linked it 5 times, most often “SQL Server Upsert Patterns and Antipatterns (2017)”. It is still writing: the last post was on 2026-08-04, and you can follow it by feed.
Too few sampled comments (4) to say how often HN recommends it.?
Why HN links it
HN commenters link Michael J. Swart's posts on SQL Server MERGE problems and upsert patterns, citing them as references for the edge cases and bugs that MERGE can hit.
Summarised by Claude from a sample of 4 HN comments that link here. Each comment is marked recommending, critical or neutral (citing without judging); how this works.
Michael J Swart's blog about all things database, free articles, tips and tricks. Mostly about SQL in general and SQL Server in particular.
Most-linked posts?
- /2021/08/what-to-avoid-if-you-want-to-use-merge/2 people · 3 mentions · first linked 2022-04-22
- SQL Server Upsert Patterns and Antipatterns (2017)2 people · 2 mentions · first linked 2020-09-04
What Hacker News says?
> Well MS SQL Merge statement is not very good That is rather an understatement. IIRC unless you are careful with transaction isolation levels and other options, a single MERGE statement can still deadlock against itself . See https://michaeljswart.com/2021/08/what-to-avoid-if-you-want-... and the older page it links to, mongst many references to the problems you can encounter. Though things are a fair amount better…
Comment linking /2021/08/what-to-avoid-if-you-want-to-use-merge/
on “PostgreSQL 15”Submitted SQL Server Upsert Patterns and Antipatterns (2017) as a story · 2 points
HN discussion> use with a merge statement in order to get an atomic upsert - holdlock in sql server Because of all the potential edge cases that MERGE didn't handle properly when introduced to SQL Server (2008?), I've avoided its use. Despite several revisions over the years there are apparently still significant behaviours that I'd consider bugs¹, some of which have been closed as WONTFIX² so are a fact of life you just have to…
Comment linking /2021/08/what-to-avoid-if-you-want-to-use-merge/
on “How Postgres chooses which index to use for a query”when I need to do some kind of upsert on SQL server, I tend to refer to this post: https://michaeljswart.com/2017/07/sql-server-upsert-patterns...
Comment linking /2017/07/sql-server-upsert-patterns-and-antipatterns/
on “Upsert anti-pattern in SQL Server”mssql merge has a lot of problems. it's good for the most basic and straightforward of use cases, but it struggles with a variety of features: https://michaeljswart.com/2021/08/what-to-avoid-if-you-want-...
Comment linking /2021/08/what-to-avoid-if-you-want-to-use-merge/
on “Upsert in SQL”