compare integer to inet

Поиск
Список
Период
Сортировка
Искать

compare integer to inet

От:
Bill MacArthur <webmaster@dhs-club.com>
Дата:
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

Re: compare integer to inet

От:
Scott Ribe <scott_ribe@elevated-dev.com>
Дата:
On Aug 19, 2011, at 4:24 PM, Bill MacArthur wrote:

> select case when '41.224.0.0'::inet = 702545920 then true else false end;

If addition works, maybe subtraction works. So subtract 0?

-- 
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Re: compare integer to inet

От:
Dimitri Fontaine <dimitri@2ndQuadrant.fr>
Дата:
Bill MacArthur  writes:
> 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).

I would then use the ip4r extension, which is very very good for that
kind of things.

  http://pgfoundry.org/projects/ip4r/

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support
FAQ