inet/cidr type comparisons - Mailing list pgsql-hackers

From Alex Pilosov
Subject inet/cidr type comparisons
Date
Msg-id Pine.BSO.4.10.10106110938370.17529-100000@spider.pilosoft.com
Whole thread Raw
Responses Re: inet/cidr type comparisons  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I noticed current wierd behaviour of a less/greater than comparisons of
things involving inet/cidr:

10.1.2.3/8 is considered to be less than 10.0.0.0/32

The current logic does the following:
a) compare the network part of each (this will be 10.0.0.0), identical in
this case.

b) compare the netmask length. If a value has shorter netmask, its
considered to be less than a value with longer netmask.

c) the host part is compared. 

To me, this makes no sense. I think b and c should be transposed, and
netmask comparison must be only used as a tiebreaker when the values are
the same otherwise (such as, when comparing 10.1.2.3/8 and 10.1.2.3/32).

For type cidr, same thing applies: currently, 10.1.2.0/24 is considered to
be less than 10.0.0.0/8. 

If someone can tell me a good reason why the comparisons are the way they
are now, I'd much appreciate it :)

-alex



pgsql-hackers by date:

Previous
From: "earthlink"
Date:
Subject: Implicit order-by in Postgresql?
Next
From: Oleg Bartunov
Date:
Subject: Re: PostgreSQL and replication