Menu

Your Postgres Get-or-Create Has a Race. Postgres 19's ON CONFLICT DO SELECT Closes It
πŸ“°

Your Postgres Get-or-Create Has a Race. Postgres 19's ON CONFLICT DO SELECT Closes It

DEV Community: postgresΒ·Gabriel AnhaiaΒ·2 days ago
#p2Tr0pRM
#devtopostgresql#devto#dev#name#insert
Reading 0:00
15s threshold

Book: Database Playbook

Also by me: Thinking in Go (2-book series) β€” Complete Guide to Go Programming + Hexagonal Architecture in Go

My project: Hermes IDE | GitHub β€” an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

Two requests to tag an article postgres arrive a few milliseconds apart. Both look up the tag. Neither finds it. Both insert it. One gets an id back. The other gets SQLSTATE 23505 , unique_violation , and your API returns a 500 for a request that did nothing wrong.

Get-or-create is the most boring query in your codebase, and the obvious ways to write it on PostgreSQL 18 are all wrong somewhere. Some race. Some return nothing. One writes to the table every time you read from it. On 12 February 2026, commit 88327092ff added INSERT ... ON CONFLICT DO SELECT , and it is in PostgreSQL 19 RC 1 , released 15 October 2026. GA is planned for 19 November 2026, barring delays.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.