Skip to main content
PHP Blog

Back to all posts

How to Count Empty Rows In Postgresql?

Published on
3 min read
How to Count Empty Rows In Postgresql? image

Best SQL Tools to Buy in October 2025

1 SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL (Coding & Programming - QuickStart Guides)

SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL (Coding & Programming - QuickStart Guides)

BUY & SAVE
$21.26 $27.99
Save 24%
SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL (Coding & Programming - QuickStart Guides)
2 SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL

SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL

BUY & SAVE
$31.36 $59.99
Save 48%
SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL
3 SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)

SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)

  • AFFORDABLE PRICES FOR QUALITY USED BOOKS PROMOTE BUDGET-FRIENDLY READING.
  • ECO-FRIENDLY CHOICE SUPPORTS SUSTAINABILITY AND REDUCES WASTE.
  • THOROUGHLY INSPECTED QUALITY GUARANTEES RELIABILITY FOR EVERY PURCHASE.
BUY & SAVE
$25.28 $34.95
Save 28%
SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)
4 Python, Java, SQL & JavaScript: The Ultimate Crash Course for Beginners to Master the 4 Most In-Demand Programming Languages, Stand Out from the Crowd and Find High-Paying Jobs!

Python, Java, SQL & JavaScript: The Ultimate Crash Course for Beginners to Master the 4 Most In-Demand Programming Languages, Stand Out from the Crowd and Find High-Paying Jobs!

BUY & SAVE
$29.99
Python, Java, SQL & JavaScript: The Ultimate Crash Course for Beginners to Master the 4 Most In-Demand Programming Languages, Stand Out from the Crowd and Find High-Paying Jobs!
5 The Definitive Guide to DAX: Business Intelligence for Microsoft Power BI, SQL Server Analysis Services, and Excel Second Edition (Business Skills)

The Definitive Guide to DAX: Business Intelligence for Microsoft Power BI, SQL Server Analysis Services, and Excel Second Edition (Business Skills)

BUY & SAVE
$32.79 $59.99
Save 45%
The Definitive Guide to DAX: Business Intelligence for Microsoft Power BI, SQL Server Analysis Services, and Excel Second Edition (Business Skills)
6 Oracle PL / SQL For Dummies

Oracle PL / SQL For Dummies

  • AFFORDABLE PRICES FOR QUALITY BOOKS IN GOOD CONDITION!
  • ENVIRONMENTALLY FRIENDLY: SAVE TREES BY BUYING USED!
  • UNIQUE FINDS: DISCOVER HIDDEN GEMS IN OUR CURATED SELECTION!
BUY & SAVE
$13.96 $31.99
Save 56%
Oracle PL / SQL For Dummies
7 SQL All-in-One For Dummies (For Dummies (Computer/Tech))

SQL All-in-One For Dummies (For Dummies (Computer/Tech))

BUY & SAVE
$24.92 $39.99
Save 38%
SQL All-in-One For Dummies (For Dummies (Computer/Tech))
+
ONE MORE?

To count empty rows in PostgreSQL, you can use a query that selects all rows and then checks for the specific condition of empty values. This can be done by using the COUNT function in combination with the WHERE clause to filter out the empty rows. For example, you can write a query like this:

SELECT COUNT(*) FROM table_name WHERE column_name IS NULL;

This query will count all the rows in the table where the specified column has a NULL value, which can be considered as an empty row in this context. You can replace "table_name" with the name of your table and "column_name" with the name of the column you are checking for empty values. This query will return the count of empty rows that meet the specified condition.

How to count empty rows in postgresql using a subselect statement?

You can count empty rows in PostgreSQL by using a subquery to first select all rows that are not empty, and then subtracting that count from the total number of rows in the table.

Here's an example query that demonstrates this approach:

SELECT COUNT(*) - (SELECT COUNT(*) FROM your_table WHERE column_name <> '') as empty_row_count FROM your_table;

In this query:

  1. your_table is the name of the table you want to count empty rows in.
  2. column_name is the name of the column you want to check for empty values (replace this with the actual column name).
  3. The subquery (SELECT COUNT(*) FROM your_table WHERE column_name <> '') selects the count of rows that are not empty in the specified column.
  4. The main query then subtracts this count from the total count of rows in the table to get the count of empty rows.

This query will return the count of empty rows in the specified table and column.

How to count empty rows in postgresql using a common table expression?

You can count empty rows in PostgreSQL using a Common Table Expression (CTE) and the COUNT function. Here's an example query to do that:

WITH empty_rows_count AS ( SELECT COUNT(*) AS empty_count FROM your_table WHERE your_column IS NULL OR your_column = '' ) SELECT empty_count FROM empty_rows_count;

In this query:

  1. Replace your_table with the name of your table and your_column with the name of the column you want to check for empty values.
  2. The CTE named empty_rows_count selects the count of rows where the specified column is either NULL or an empty string.
  3. Finally, the outer SELECT statement retrieves the count of empty rows from the CTE.

You can run this query in your PostgreSQL database to count the empty rows in the specified table and column.

How to count empty rows in postgresql using the count function?

To count empty rows in PostgreSQL using the count function, you can write a query that checks for rows where all columns are NULL. Here's an example query that counts empty rows in a table called "example_table":

SELECT COUNT(*) AS empty_rows FROM example_table WHERE column1 IS NULL AND column2 IS NULL AND column3 IS NULL -- Add more columns as needed

This query will return the number of rows in "example_table" where all specified columns are NULL. You can customize the query to include additional columns that you want to check for NULL values.