Recently I was looking at options for exploring CIDR blocks in PostgreSQL. In particular, I was wondering about checking a CIDR block for unallocated IP addresses in another table.

I had been aware of network address types in PostgreSQL for some time but had not been aware of how powerful they actually were. I decided to write a function to expand a CIDR bock into a list of IP blocks. While my initial version wasn't perfect (it includes network and broadcast addresses in the block), changing that will not be hard.