| PostgreSQL Reference Manual - Volume 1 - SQL Language Reference by The PostgreSQL Global Development Group Paperback (6"x9"), 716 pages ISBN 0954612027 RRP £32.00 ($49.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
7.17.5 Row-wise Comparison
row_constructor operator row_constructor
Each side is a row constructor,
as described in section 2.2.11 Row Constructors.
The two row values must have the same number of fields.
Each side is evaluated and they are compared row-wise. Row comparisons
are allowed when the operator is
=,
<>,
<,
<=,
> or
>=,
or has semantics similar to one of these. (To be specific, an operator
can be a row comparison operator if it is a member of a B-Tree operator
class, or is the negator of the = member of a B-Tree operator
class.)
The = and <> cases work slightly differently
from the others. Two rows are considered
equal if all their corresponding members are non-null and equal; the rows
are unequal if any corresponding members are non-null and unequal;
otherwise the result of the row comparison is unknown (null).
For the <, <=, > and
>= cases, the row elements are compared left-to-right,
stopping as soon as an unequal or null pair of elements is found.
If either of this pair of elements is null, the result of the
row comparison is unknown (null); otherwise comparison of this pair
of elements determines the result. For example,
ROW(1,2,NULL) < ROW(1,3,0)
yields true, not null, because the third pair of elements are not
considered.
Note: Prior to PostgreSQL 8.2, the
<,<=,>and>=cases were not handled per SQL specification. A comparison likeROW(a,b) < ROW(c,d)was implemented asa < c AND b < dwhereas the correct behavior is equivalent toa < c OR (a = c AND b < d).
row_constructor IS DISTINCT FROM row_constructor
This construct is similar to a <> row comparison,
but it does not yield null for null inputs. Instead, any null value is
considered unequal to (distinct from) any non-null value, and any two
nulls are considered equal (not distinct). Thus the result will always
be either true or false, never null.
row_constructor IS NOT DISTINCT FROM row_constructor
This construct is similar to a = row comparison,
but it does not yield null for null inputs. Instead, any null value is
considered unequal to (distinct from) any non-null value, and any two
nulls are considered equal (not distinct). Thus the result will always
be either true or false, never null.
| ISBN 0954612027 | PostgreSQL Reference Manual - Volume 1 - SQL Language Reference | See the print edition |