Friday, March 15, 2013

Displaying ip addresses in postgres

If you have ipv4 addresses stored as integers in a postgres database, you can display the address using the trick '0.0.0.0'::inet + ip. For example:


     select distinct ('0.0.0.0'::inet + devaddr) as addr from interface
        order by addr;