Re: Help creating a function

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Help creating a function
Date: 2007-08-20 11:21:50
Message-ID: 20070820112149.GE1735@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2007-08-20 13:00:01 Re: POSTGRE CRASH AND CURRVAL PROBLEM HELP!
Previous Message Jayaprakash, Sowmiya Lakshmi (STSD) 2007-08-20 10:42:53 Solution to Bus error(coredump) from postgres binary