Postgresql Rocks

Postgresql supports a data type "inet". Inet allows you to insert ip addresses into the table, and then later run operations against the host/network ranges. A while back I accidentally created a schema using the inet data type, today I was able to search for transactions based on a subnet mask (yes it's very cool).

select tochar(date, 'YYYY-MM-DD') as date, round(sum(size)/2/1073741824,3) as size, account, appuid, clientip from proftpd where method = 'RETR' and tochar(date, 'YYYY-MM') = '2004-03' and clientip << inet '' group by to_char(date, 'YYYY-MM-DD'), account, appuid, clientip;

That "clientip << inet ''" section is key. It says where clientip is in the subnet or has a ip address.