Re: inet to bigint?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: inet to bigint?
Date: 2005-12-06 07:44:28
Message-ID: 20051206074428.GA76801@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 06, 2005 at 03:31:59PM +0800, Christopher Kings-Lynne wrote:
> OK, I give up - how do I convert an INET type to a NUMERIC
> representation of its network address?

How about:

CREATE FUNCTION inet2num(inet) RETURNS numeric AS $$
use Socket;
return unpack("N", inet_aton($_[0]));
$$ LANGUAGE plperlu IMMUTABLE STRICT;

SELECT inet2num('127.0.0.1');
inet2num
------------
2130706433
(1 row)

--
Michael Fuhr

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message hubert depesz lubaczewski 2005-12-06 07:48:53 Re: inet to bigint?
Previous Message Christopher Kings-Lynne 2005-12-06 07:31:59 inet to bigint?