Re: Help creating a function - Mailing list pgsql-general

From A. Kretschmer
Subject Re: Help creating a function
Date
Msg-id 20070820112149.GE1735@a-kretschmer.de
Whole thread Raw
In response to Help creating a function  (Madison Kelly <linux@alteeve.com>)
List pgsql-general
am  Wed, dem 15.08.2007, um 17:29:17 -0400 mailte Madison Kelly folgendes:
>   What I would like to do is create a function that would do the same
> thing so I could read out the IP addresses as standard dotted-decimal
> format. Could anyone help me with this? I am quite the n00b when it
> comes to functions. :)

create or replace function bigint2inet(IN i bigint, OUT n inet) as $$
declare a int;
        b int;
        c int;
        d int;
begin
        a := i/(256^3)::int;
        b := ((i-(256^3)*a)/(256^2))::int;
        c := ((i-(256^3)*a-(256^2)*b)/256)::int;
        d := (i-(256^3)*a-(256^2)*b-256*c)::int;
        n := (a||'.'||b||'.'||c||'.'||d)::inet;
        return;
end;
$$ language plpgsql immutable strict;


hope thats helps, Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: Andrei Kovalevski
Date:
Subject: Re: Installation problems
Next
From: "Merlin Moncure"
Date:
Subject: Re: POSTGRE CRASH AND CURRVAL PROBLEM HELP!