Null values in PostgreSQL

Prathap Chandra
1 min readMar 27, 2022

--

Photo by Sunder Muthukumaran on Unsplash

PostgreSQL uses a fixed page size (commonly 8 kB) and does not allow rows to span multiple pages.

So the smaller the size of our record, the more rows we can cram into the page. The more number of records on a single page, the less I/O time in doing range queries resulting in a faster response time.

Unlike Oracle, PostgreSQL allows indexing null values. We can create a partial index on the column excluding nulls and have tight indexing thus resulting in a faster response time.

When in doubt, Store nulls.

Create a table and add a few records to it. make sure one of the columns contains both null values and some data. Now execute the following queries and you’ll see something interesting

select count(*) from table this will include nulls, but select count(some specific column) from table will not include nulls.

Although this is a very short one, I’ve decided to document it. I’ll be writing a series of articles on different database topics in the coming weeks. Please feel free to add if I miss anything.

You can connect with me on LinkedIn, Twitter, and Instagram.

--

--

Prathap Chandra
Prathap Chandra

No responses yet