PostgreSQL - How to check if a row exist in a table?

You have a table customers and want to check if there's already a row with id = 100 existing.

You can use COUNT to check:

SELECT COUNT(*) FROM customers WHERE id = 100;

But if you are looking for a faster query with a yes/no answer:

SELECT EXISTS(SELECT 1 FROM customers WHERE id = 100);
Check if row exists in a table

Need a good GUI tool for PostgreSQL? Check out TablePlus. It's native, beautiful, and available for free.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus GUI Tool PostgreSQL

← All posts