Postgres 15 Merge Command with Examples

  • This will make complex upserts so much more simple, fantastic addition.

    I really hope `RETURNING` support gets added to `MERGE` asap though (I believe it's been noted as a fairly trivial addition to come in future), then it'll be super powerful for doing bulk upserts that require post-processing.

  • > prior to Postgres 15, you could use the "upsert" method with the ON CONFLICTclause.

    > Now, MERGE can be used instead!

    No mention of deadlocks in the article has me worried about thoroughness of the analysis.

  • This sounds really cool; maybe slightly cleaner than an INSERT ... ON CONFLICT statement. However, is that the only advantage?

  • Great to see!

    My biggest gripe with ON CONFLICT upserts are the IDs (sequences) having gaps in them. Any good ways to prevent that?

  • In SqlServer you have to use MERGE with HOLDLOCK to avoid issues, is it possible in Postgres? Is it so by default?

  • This is one of my favorite features in snowflake (I’m assuming they didn’t invent it) and am happy to see it in Postgres now.

  • Awesome. How the hell did it take 20 years to finally land?