How to convert a bigint into an inet in postgresql ?
IPv4 adresses are typically bigint data - they are 32-bits data usually written as 4 blocks of 8 bits for practical reasons.
My version of postgresl doesn’t know how to translate this bigint natively into an inet, so I’m using the following trick:
select
((3221226219 & x’ff000000′::bigint >> 24 ) || ‘.’ ||
(3221226219 & x’00ff0000′::bigint >> 16 ) || ‘.’ ||
(3221226219 & x’0000ff00′::bigint >> 8 ) || ‘.’ ||
(3221226219 & x’000000ff’::bigint))::inet