Created
June 16, 2015 08:10
-
-
Save zmij/1c90a2af3445f363ca83 to your computer and use it in GitHub Desktop.
Cast inet to bigint and back
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function bigint_to_inet (intaddr bigint) returns inet | |
as | |
$BODY$ | |
begin | |
return '0.0.0.0'::inet + intaddr; | |
end | |
$BODY$ | |
language plpgsql immutable strict; | |
create cast (bigint as inet) with function bigint_to_inet(bigint); | |
create or replace function inet_to_bigint (addr inet) returns bigint | |
as | |
$BODY$ | |
begin | |
return addr - '0.0.0.0'; | |
end | |
$BODY$ | |
language plpgsql immutable strict; | |
create cast (inet as bigint) with function inet_to_bigint(inet); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment