pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bill MacArthur <webmaster@dhs-club.com>
To: pgsql-admin@postgresql.org
Subject: compare integer to inet
Date: Fri, 19 Aug 2011 18:24:31 -0400
Message-ID: <4E4EE29F.2070209@dhs-club.com> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <4E4EE29F.2070209@dhs-club.com>
Permalink:  ../4E4EE29F.2070209@dhs-club.com/
Also on:    postgresql.org/message-id/4E4EE29F.2070209@dhs-club.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: webmaster@dhs-club.com
  Subject: Re: compare integer to inet
  In-Reply-To: <4E4EE29F.2070209@dhs-club.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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