compare integer to inet

From: Bill MacArthur <webmaster(at)dhs-club(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: compare integer to inet
Date: 2011-08-19 22:24:31
Message-ID: 4E4EE29F.2070209@dhs-club.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Greetings,

Considering that this can be done:

network=# SELECT '0.0.0.0'::inet + 702545920;
?column?
------------
41.224.0.0
(1 row)

How can I perform an operation similar to this that works?

network=# select case when '41.224.0.0'::inet = 702545920 then true else false end;
ERROR: operator does not exist: inet = integer
LINE 1: select case when '41.224.0.0'::inet = 702545920 then true el...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

network=# select case when '41.224.0.0'::inet = 702545920::inet then true else false end;
ERROR: cannot cast type integer to inet
LINE 1: select case when '41.224.0.0'::inet = 702545920::inet then t...

I'm guessing that there is some internal postgres function that performs the integer to IP address conversion in the first example, but I am at a loss to identify it.

The reason I ask for this is that we have a dataset that contains ranges of IP addresses, associated with countries, where the addresses are represented as integers (bigints).

Thanks for the pointer.

Bill MacArthur

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Scott Ribe 2011-08-20 00:20:13 Re: compare integer to inet
Previous Message Marko Kreen 2011-08-19 18:00:27 Re: Londiste won't start with dual IP addresses