Operators
&&
Returns TRUE if A's bounding box overlaps B's.
boolean &&
geometry
A
geometry
B
boolean &&
geography
A
geography
B
Description
The && operator returns TRUE if the bounding box of geometry A overlaps the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Availability: 1.5.0 support for geography was introduced.
&curve_support;
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 && tbl2.column2 AS overlaps
FROM ( VALUES
(1, 'LINESTRING(0 0, 3 3)'::geometry),
(2, 'LINESTRING(0 1, 0 5)'::geometry)) AS tbl1,
( VALUES
(3, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2;
column1 | column1 | overlaps
---------+---------+----------
1 | 3 | t
2 | 3 | f
(2 rows)
See Also
,
,
,
,
,
&<
Returns TRUE if A's bounding box overlaps or is to the left of B's.
boolean &<
geometry
A
geometry
B
Description
The &< operator returns TRUE if the bounding box of geometry A
overlaps or is to the left of the bounding box of geometry B, or more accurately, overlaps or is NOT to the right
of the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 &< tbl2.column2 AS overleft
FROM
( VALUES
(1, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING(0 0, 3 3)'::geometry),
(3, 'LINESTRING(0 1, 0 5)'::geometry),
(4, 'LINESTRING(6 0, 6 1)'::geometry)) AS tbl2;
column1 | column1 | overleft
---------+---------+----------
1 | 2 | f
1 | 3 | f
1 | 4 | t
(3 rows)
See Also
,
,
,
&<|
Returns TRUE if A's bounding box overlaps or is below B's.
boolean &<|
geometry
A
geometry
B
Description
The &<| operator returns TRUE if the bounding box of geometry A
overlaps or is below of the bounding box of geometry B, or more accurately, overlaps or is NOT above the bounding
box of geometry B.
&curve_support;
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 &<| tbl2.column2 AS overbelow
FROM
( VALUES
(1, 'LINESTRING(6 0, 6 4)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING(0 0, 3 3)'::geometry),
(3, 'LINESTRING(0 1, 0 5)'::geometry),
(4, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2;
column1 | column1 | overbelow
---------+---------+-----------
1 | 2 | f
1 | 3 | t
1 | 4 | t
(3 rows)
See Also
,
,
,
&>
Returns TRUE if A' bounding box overlaps or is to the right of B's.
boolean &>
geometry
A
geometry
B
Description
The &> operator returns TRUE if the bounding box of geometry A
overlaps or is to the right of the bounding box of geometry B, or more accurately, overlaps or is NOT to the left
of the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 &> tbl2.column2 AS overright
FROM
( VALUES
(1, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING(0 0, 3 3)'::geometry),
(3, 'LINESTRING(0 1, 0 5)'::geometry),
(4, 'LINESTRING(6 0, 6 1)'::geometry)) AS tbl2;
column1 | column1 | overright
---------+---------+-----------
1 | 2 | t
1 | 3 | t
1 | 4 | f
(3 rows)
See Also
,
,
,
<<
Returns TRUE if A's bounding box is strictly to the left of B's.
boolean <<
geometry
A
geometry
B
Description
The << operator returns TRUE if the bounding box of geometry A
is strictly to the left of the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 << tbl2.column2 AS left
FROM
( VALUES
(1, 'LINESTRING (1 2, 1 5)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (0 0, 4 3)'::geometry),
(3, 'LINESTRING (6 0, 6 5)'::geometry),
(4, 'LINESTRING (2 2, 5 6)'::geometry)) AS tbl2;
column1 | column1 | left
---------+---------+------
1 | 2 | f
1 | 3 | t
1 | 4 | t
(3 rows)
See Also
, ,
<<|
Returns TRUE if A's bounding box is strictly below B's.
boolean <<|
geometry
A
geometry
B
Description
The <<| operator returns TRUE if the bounding box of geometry A
is strictly below the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 <<| tbl2.column2 AS below
FROM
( VALUES
(1, 'LINESTRING (0 0, 4 3)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (1 4, 1 7)'::geometry),
(3, 'LINESTRING (6 1, 6 5)'::geometry),
(4, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl2;
column1 | column1 | below
---------+---------+-------
1 | 2 | t
1 | 3 | f
1 | 4 | f
(3 rows)
See Also
, ,
=
Returns TRUE if A's bounding box is the same as B's.
boolean =
geometry
A
geometry
B
Description
The = operator returns TRUE if the bounding box of geometry A
is the same as the bounding box of geometry B. PostgreSQL uses the =, <, and > operators defined for geometries to
perform internal orderings and comparison of geometries (ie. in a GROUP BY or ORDER BY clause).
This is cause for a lot of confusion. When you compare geometryA =
geometryB it will return true even when the geometries are clearly
different IF their bounding boxes are the same. To check for true
equality use or
This operand will NOT make use of any indexes that may be available on the
geometries.
&curve_support;
Examples
SELECT 'LINESTRING(0 0, 0 1, 1 0)'::geometry = 'LINESTRING(1 1, 0 0)'::geometry;
?column?
----------
t
(1 row)
SELECT ST_AsText(column1)
FROM ( VALUES
('LINESTRING(0 0, 1 1)'::geometry),
('LINESTRING(1 1, 0 0)'::geometry)) AS foo;
st_astext
---------------------
LINESTRING(0 0,1 1)
LINESTRING(1 1,0 0)
(2 rows)
-- Note: the GROUP BY uses the "=" to compare for geometry equivalency.
SELECT ST_AsText(column1)
FROM ( VALUES
('LINESTRING(0 0, 1 1)'::geometry),
('LINESTRING(1 1, 0 0)'::geometry)) AS foo
GROUP BY column1;
st_astext
---------------------
LINESTRING(0 0,1 1)
(1 row)
See Also
, ,
>>
Returns TRUE if A's bounding box is strictly to the right of B's.
boolean >>
geometry
A
geometry
B
Description
The >> operator returns TRUE if the bounding box of geometry A
is strictly to the right of the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 >> tbl2.column2 AS right
FROM
( VALUES
(1, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (1 4, 1 7)'::geometry),
(3, 'LINESTRING (6 1, 6 5)'::geometry),
(4, 'LINESTRING (0 0, 4 3)'::geometry)) AS tbl2;
column1 | column1 | right
---------+---------+-------
1 | 2 | t
1 | 3 | f
1 | 4 | f
(3 rows)
See Also
, ,
@
Returns TRUE if A's bounding box is contained by B's.
boolean ~=
geometry
A
geometry
B
Description
The @ operator returns TRUE if the bounding box of geometry A is completely
contained by the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 @ tbl2.column2 AS contained
FROM
( VALUES
(1, 'LINESTRING (1 1, 3 3)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (0 0, 4 4)'::geometry),
(3, 'LINESTRING (2 2, 4 4)'::geometry),
(4, 'LINESTRING (1 1, 3 3)'::geometry)) AS tbl2;
column1 | column1 | contained
---------+---------+-----------
1 | 2 | t
1 | 3 | f
1 | 4 | t
(3 rows)
See Also
,
|&>
Returns TRUE if A's bounding box overlaps or is above B's.
boolean |&>
geometry
A
geometry
B
Description
The |&> operator returns TRUE if the bounding box of geometry A
overlaps or is above the bounding box of geometry B, or more accurately, overlaps or is NOT below
the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 |&> tbl2.column2 AS overabove
FROM
( VALUES
(1, 'LINESTRING(6 0, 6 4)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING(0 0, 3 3)'::geometry),
(3, 'LINESTRING(0 1, 0 5)'::geometry),
(4, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2;
column1 | column1 | overabove
---------+---------+-----------
1 | 2 | t
1 | 3 | f
1 | 4 | f
(3 rows)
See Also
,
,
,
|>>
Returns TRUE if A's bounding box is strictly above B's.
boolean |>>
geometry
A
geometry
B
Description
The |>> operator returns TRUE if the bounding box of geometry A
is strictly to the right of the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 |>> tbl2.column2 AS above
FROM
( VALUES
(1, 'LINESTRING (1 4, 1 7)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (0 0, 4 2)'::geometry),
(3, 'LINESTRING (6 1, 6 5)'::geometry),
(4, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl2;
column1 | column1 | above
---------+---------+-------
1 | 2 | t
1 | 3 | f
1 | 4 | f
(3 rows)
See Also
, ,
~
Returns TRUE if A's bounding box contains B's.
boolean ~
geometry
A
geometry
B
Description
The ~ operator returns TRUE if the bounding box of geometry A completely
contains the bounding box of geometry B.
This operand will make use of any indexes that may be available on the
geometries.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 ~ tbl2.column2 AS contains
FROM
( VALUES
(1, 'LINESTRING (0 0, 3 3)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (0 0, 4 4)'::geometry),
(3, 'LINESTRING (1 1, 2 2)'::geometry),
(4, 'LINESTRING (0 0, 3 3)'::geometry)) AS tbl2;
column1 | column1 | contains
---------+---------+----------
1 | 2 | f
1 | 3 | t
1 | 4 | t
(3 rows)
See Also
,
~=
Returns TRUE if the geometry A is the same as B.
boolean ~=
geometry
A
geometry
B
boolean ~=
geography
A
geography
B
Description
The ~= operator returns TRUE if geometry A is the same as geometry B.
It tests actual geometric equality of two features. So if A and B are the same feature, vertex-by-vertex, the
operator returns TRUE.
This operand will make use of any indexes that may be available on the
geometries.
Availability: 1.5.0 support for geography was introduced.
Examples
SELECT tbl1.column1, tbl2.column1, tbl1.column2 ~= tbl2.column2 AS same
FROM
( VALUES
(1, 'LINESTRING (0 0, 2 2)'::geometry)) AS tbl1,
( VALUES
(2, 'LINESTRING (0 0, 1 1, 2 2)'::geometry),
(3, 'LINESTRING (2 2, 0 0)'::geometry),
(4, 'LINESTRING (0 0, 2 2)'::geometry)) AS tbl2;
column1 | column1 | same
---------+---------+------
1 | 2 | f
1 | 3 | f
1 | 4 | t
(3 rows)
See Also
, ,