Re: Comparing first 3 numbers of a IPv4 address?

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Comparing first 3 numbers of a IPv4 address?
Date: 2010-11-30 18:33:13
Message-ID: id3g19$ipe$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2010-11-20, Alexander Farber <alexander(dot)farber(at)gmail(dot)com> wrote:

>
> 1) if I'd like to compare just the first 3 numbers of
> the IP address instead of the 4, how can I do it?
> (yes, I know about the A,B,C type of IPv4 networks...)

have you heard of CIDR (what about IPV6, which I'm going to ignore,
but you should consider unless this code is throw-away)

just use set_masklen and the >> operator.

select set_masklen('1.2.3.4'::inet,24) >> '1.2.3.244'::inet;

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-11-30 18:48:39 Re: [GENERAL] column-level update privs + lock table
Previous Message Robert Haas 2010-11-30 18:22:31 Re: [GENERAL] column-level update privs + lock table