EN
PostgreSQL - find rows where column is empty string (blank)
0 points
In this article, we would like to show you how to find rows where the column value is an empty string in PostgreSQL.
Quick solution:
xxxxxxxxxx
1
SELECT * FROM "table_name" WHERE "column_name" = '';
If your column is NULL then the below query works:
xxxxxxxxxx
1
SELECT * FROM "table_name" WHERE "column_name" IS NULL;
To show how to find rows where the column value is an empty string, we will use the following table:

Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will find rows from users
table with empty email
column.
Query:
xxxxxxxxxx
1
SELECT *
2
FROM "users"
3
WHERE "email" = '';
Result:

create_tables.sql
file:
xxxxxxxxxx
1
CREATE TABLE "users" (
2
"id" SERIAL,
3
"name" VARCHAR(50) NOT NULL,
4
"surname" VARCHAR(50) NOT NULL,
5
"email" VARCHAR(50),
6
PRIMARY KEY ("id")
7
);
insert_data.sql
file:
xxxxxxxxxx
1
INSERT INTO "users"
2
( "name", "surname", "email")
3
VALUES
4
('John', 'Stewart', 'john@email.com'),
5
('Chris', 'Brown', ''),
6
('Kate', 'Lewis',''),
7
('Ailisa', 'Gomez', 'ailisa@email.com'),
8
('Gwendolyn', 'James', ''),
9
('Simon', 'Collins', ''),
10
('Taylor', 'Martin',''),
11
('Andrew', 'Thompson', 'andrew123@email.com');