Re: int to inet conversion [or Re: inet to bigint?]

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Kai <kai(at)xs4all(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: int to inet conversion [or Re: inet to bigint?]
Date: 2005-12-10 03:34:56
Message-ID: 439A4CE0.3000809@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Kai,

There are some rather simplistic functions to convert 32bit inet values
to and from bigints in the mysql compatibility project:

http://pgfoundry.org/projects/mysqlcompat/

In the miscellaneous.sql.

Chris

Kai wrote:
> Hello All,
>
> I've been pondering the discussed subject a few times, and came along a few
> things that I think are missing from the default set of typeconversions
> within postgres.
>
> After working regularly with inet values in sql, it would be nice to be able
> to do this:
>
> => select '192.168.1.1'::inet + 1 as result;
> result
> -------------
> 192.168.1.2
> (1 row)
>
> => select '192.168.1.255'::inet - '192.168.1.0'::inet as difference;
> difference
> ----------------
> 255
> (1 row)
>
> or simply this:
>
> => select '192.168.1.1'::inet::bigint
> bigint
> ------------
> 3232235777
>
>
> In the old postgres 7.3 the data was stored in the database being a big
> integer anyway, but in the new ipv6 compatible stuff I lost track. I can
> probably write the functions in C if theres more interest in them, but I'm
> not on track on how to define all the casting stuff in the postgresql system
> tables, nor the sticky subject on how to handle ipv6.
>
>
> Or maybe someone else was pondering the idea too and is far better at
> writing C? :-)
>
>
> My conclusion is that the selects above should be among the default set of
> operations on inet values in PostgreSQL, being subtraction and addition. If
> not I'd like to be proven wrong.
>
>
> Regards,
>
>
> Kai
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Guillaume LELARGE 2005-12-10 08:47:13 Something I don't understand with the use of schemas
Previous Message Stephan Szabo 2005-12-10 01:27:32 Re: Foreign key trigger timing bug?