Updated on 2025-05-29 GMT+08:00

cidr and inet Operators

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.

<

Description: Is less than

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' < inet '192.168.1.6' AS RESULT;
 result 
--------
 t
(1 row)

<=

Description: Is less than or equals

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' <= inet '192.168.1.5' AS RESULT;
 result 
--------
 t
(1 row)

=

Description: Equals

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' = inet '192.168.1.5' AS RESULT;
 result 
--------
 t
(1 row)

>=

Description: Is greater than or equals

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' >= inet '192.168.1.5' AS RESULT;
 result 
--------
 t
(1 row)

>

Description: Is greater than

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' > inet '192.168.1.4' AS RESULT;
 result 
--------
 t
(1 row)

<>

Description: Does not equal

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' <> inet '192.168.1.4' AS RESULT;
 result 
--------
 t
(1 row)

<<

Description: Is contained in

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.5' << inet '192.168.1/24' AS RESULT;
 result 
--------
 t
(1 row)

<<=

Description: Is contained in or equals

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1/24' <<= inet '192.168.1/24' AS RESULT;
 result 
--------
 t
(1 row)

>>

Description: Contains

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1/24' >> inet '192.168.1.5' AS RESULT;
 result 
--------
 t
(1 row)

>>=

Description: Contains or equals

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1/24' >>= inet '192.168.1/24' AS RESULT;
 result 
--------
 t
(1 row)

~

Description: Bitwise NOT

Example:

1
2
3
4
5
gaussdb=# SELECT ~ inet '192.168.1.6' AS RESULT; 
    result     
---------------
 63.87.254.249
(1 row)

&

Description: Performs an AND operation on each bit of the two network addresses.

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.6' & inet '10.0.0.0' AS RESULT;
 result  
---------
 0.0.0.0
(1 row)

|

Description: Performs an OR operation on each bit of the two network addresses.

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.6' | inet '10.0.0.0' AS RESULT;
   result    
-------------
 202.168.1.6
(1 row)

+

Description: Addition

Example:

1
2
3
4
5
gaussdb=# SELECT inet '192.168.1.6' + 25 AS RESULT;
    result    
--------------
 192.168.1.31
(1 row)

-

  • Description: Subtraction

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT inet '192.168.1.43' - 36 AS RESULT;
       result    
    -------------
     192.168.1.7
    (1 row)
    
  • Description: Subtraction

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT inet '192.168.1.43' - inet '192.168.1.19' AS RESULT;
     result 
    --------
         24
    (1 row)