# How to Get or Create in PostgreSQL

DevFeed: [How to Get or Create in PostgreSQL](<https://devfeed.tech/articles/how-to-get-or-create-in-postgresql-33922.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-get-or-create>)

Author: Haki Benita

Published: 2024-08-04T21:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [data](<https://devfeed.tech/tags/data.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

This tutorial explains how to implement an idempotent "get or create" operation in PostgreSQL. It distinguishes the operation from UPSERT and examines unique constraints, existing-row checks, race conditions, concurrency issues, and possible table bloat.

## Source excerpt

"Get or create" is a very common operation for syncing data in the database, but implementing it correctly may be trickier than you may expect. If you ever had to implement it in a real system with real-life load, you may have overlooked potential race conditions, concurrency issues and even bloat!