PostgreSQL - How to check if a row exist in a table?
You have a table address
and want to check if there’s already a row with address_id = 100
existing.
You can use COUNT
to check:
SELECT COUNT(*) FROM address WHERE address_id = 100;
But if you are looking for a faster query with a yes/no answer:
SELECT EXISTS(SELECT 1 FROM address WHERE address_id = 100);
Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.