inet_ntoa and inet_aton functions for Postgresql
Posted by sergey - 31/03/09 at 02:03:43 pmThese functions can be used to convert integer to ip and visa verse. This sometimes also called inet_itoa and inet_atoi.
create or replace function inet_aton(inet) returns bigint as '
select inetmi($1,''0.0.0.0'');'
language sql immutable;
create or replace function inet_ntoa(int) returns inet as '
select ''0.0.0.0''::inet+$1;'
language sql immutable;
=> select inet_ntoa(16843265);
inet_itoa
———–
1.1.2.1
(1 row)
=> select inet_aton(’1.1.2.1′);
inet_atoi
———–
16843265
(1 row)
March 31, 2009 | In recipes |
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment