The geometric types point
, box
,
lseg
, line
, path
,
polygon
, and circle
have a large set of
native support functions and operators, shown in Table 9.33, Table 9.34, and Table 9.35.
Note that the “same as” operator, ~=
, represents
the usual notion of equality for the point
,
box
, polygon
, and circle
types.
Some of these types also have an =
operator, but
=
compares
for equal areas only. The other scalar comparison operators
(<=
and so on) likewise compare areas for these types.
Table 9.33. Geometric Operators
Before PostgreSQL 8.2, the containment
operators @>
and <@
were respectively
called ~
and @
. These names are still
available, but are deprecated and will eventually be removed.
Table 9.34. Geometric Functions
Table 9.35. Geometric Type Conversion Functions
It is possible to access the two component numbers of a point
as though the point were an array with indexes 0 and 1. For example, if
t.p
is a point
column then
SELECT p[0] FROM t
retrieves the X coordinate and
UPDATE t SET p[1] = ...
changes the Y coordinate.
In the same way, a value of type box
or lseg
can be treated
as an array of two point
values.
The area
function works for the types
box
, circle
, and path
.
The area
function only works on the
path
data type if the points in the
path
are non-intersecting. For example, the
path
'((0,0),(0,1),(2,1),(2,2),(1,2),(1,0),(0,0))'::PATH
will not work; however, the following visually identical
path
'((0,0),(0,1),(1,1),(1,2),(2,2),(2,1),(1,1),(1,0),(0,0))'::PATH
will work. If the concept of an intersecting versus
non-intersecting path
is confusing, draw both of the
above path
s side by side on a piece of graph paper.