pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
compare integer to inet
3+ messages / 3 participants
[nested] [flat]

* compare integer to inet
@ 2011-08-19 22:24 Bill MacArthur <webmaster@dhs-club.com>
  2011-08-20 00:20 ` Re: compare integer to inet Scott Ribe <scott_ribe@elevated-dev.com>
  2011-08-21 19:34 ` Re: compare integer to inet Dimitri Fontaine <dimitri@2ndQuadrant.fr>
  0 siblings, 2 replies; 3+ messages in thread

From: Bill MacArthur @ 2011-08-19 22:24 UTC (permalink / raw)
  To: 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: compare integer to inet
  2011-08-19 22:24 compare integer to inet Bill MacArthur <webmaster@dhs-club.com>
@ 2011-08-20 00:20 ` Scott Ribe <scott_ribe@elevated-dev.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Scott Ribe @ 2011-08-20 00:20 UTC (permalink / raw)
  To: Bill MacArthur <webmaster@dhs-club.com>; +Cc: pgsql-admin

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







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: compare integer to inet
  2011-08-19 22:24 compare integer to inet Bill MacArthur <webmaster@dhs-club.com>
@ 2011-08-21 19:34 ` Dimitri Fontaine <dimitri@2ndQuadrant.fr>
  1 sibling, 0 replies; 3+ messages in thread

From: Dimitri Fontaine @ 2011-08-21 19:34 UTC (permalink / raw)
  To: Bill MacArthur <webmaster@dhs-club.com>; +Cc: pgsql-admin

Bill MacArthur <webmaster@dhs-club.com> 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-08-21 19:34 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 22:24 compare integer to inet Bill MacArthur <webmaster@dhs-club.com>
2011-08-20 00:20 ` Scott Ribe <scott_ribe@elevated-dev.com>
2011-08-21 19:34 ` Dimitri Fontaine <dimitri@2ndQuadrant.fr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox