From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | michel(at)albert(dot)lu |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #11734: The "<<=" operator on "inet" values does not return the expected result. |
Date: | 2014-10-21 17:55:33 |
Message-ID: | 7717.1413914133@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
michel(at)albert(dot)lu writes:
> The best way to explain this is with a quick example script:
> CREATE TABLE inettest (
> value inet UNIQUE
> );
> INSERT INTO inettest VALUES
> ('1.2.1.0/24'),
> ('1.2.1.1/24'),
> ('1.2.1.2/24'),
> ('1.2.2.0/24'),
> ('1.2.3.0/24'),
> ('1.2.3.1/24'),
> ('1.2.3.2/24'),
> ('1.2.3.3/24'),
> ('1.2.3.4/24')
> ;
> SELECT * FROM inettest WHERE value <<= '1.2.3.1/24'::inet;
> I would expect that the above select would only return *one* row. The one
> with the host '1.2.3.1/24'. Instead, it returns *all* rows of the
> '1.2.3.0/24' network.
The PG documentation is pretty clear on this point:
The operators <<, <<=, >>, >>=, and && test for subnet inclusion. They
consider only the network parts of the two addresses (ignoring any host
part) and determine whether one network is identical to or a subnet of
the other.
[ first para in "Network Address Functions and Operators" ]
So <<= should return true for any two of the addresses you cite here.
Personally I'd use CIDR, not INET, for anything I was thinking of as a
network ID rather than a single host's ID.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | John R Pierce | 2014-10-21 18:02:11 | Re: 32 bit libpq fail to connecting when set a very large "connect_timeout" value |
Previous Message | Kevin Grittner | 2014-10-21 17:55:24 | Re: BUG #11732: Non-serializable outcomes under serializable isolation |