inet_ntoa and inet_aton functions for Postgresql

These 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)

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word