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 08:09:01
Message-ID: 20051206080901.GA77212@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 06, 2005 at 01:05:12AM -0700, Michael Fuhr wrote:
> CREATE FUNCTION inet2num(inet) RETURNS numeric AS $$
> DECLARE
> a text[] := string_to_array(host($1), '.');
> BEGIN
> RETURN a[1]::numeric * 16777216 +
> a[2]::numeric * 65536 +
> a[3]::numeric * 256 +
> a[4]::numeric;
> END;
> $$ LANGUAGE plpgsql IMMUTABLE STRICT;

I should point out that this is only for IPv4, so a family() check
might be in order.

--
Michael Fuhr

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Christopher Kings-Lynne 2005-12-06 08:10:22 Re: inet to bigint?
Previous Message Michael Fuhr 2005-12-06 08:05:12 Re: inet to bigint?