The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference
by The PostgreSQL Global Development Group Paperback (6"x9"), 454 pages ISBN 9781906966041 RRP £14.95 ($19.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |

### 7.20.4 ANY/SOME

expressionoperatorANY (subquery)expressionoperatorSOME (subquery)

The right-hand side is a parenthesized
subquery, which must return exactly one column. The left-hand expression
is evaluated and compared to each row of the subquery result using the
given `operator`, which must yield a Boolean
result.
The result of `ANY`

is “true” if any true result is obtained.
The result is “false” if no true result is found (including the
case where the subquery returns no rows).

`SOME`

is a synonym for `ANY`

.
`IN`

is equivalent to `= ANY`

.

Note that if there are no successes and at least one right-hand row yields
null for the operator's result, the result of the `ANY`

construct
will be null, not false.
This is in accordance with SQL's normal rules for Boolean combinations
of null values.

As with `EXISTS`

, it's unwise to assume that the subquery will
be evaluated completely.

row_constructoroperatorANY (subquery)row_constructoroperatorSOME (subquery)

The left-hand side of this form of `ANY`

is a row constructor,
as described in section 2.2.12 Row Constructors.
The right-hand side is a parenthesized
subquery, which must return exactly as many columns as there are
expressions in the left-hand row. The left-hand expressions are
evaluated and compared row-wise to each row of the subquery result,
using the given `operator`.
The result of `ANY`

is “true” if the comparison
returns true for any subquery row.
The result is “false” if the comparison returns false for every
subquery row (including the case where the subquery returns no
rows).
The result is NULL if the comparison does not return true for any row,
and it returns NULL for at least one row.

See section 7.21.5 Row-wise Comparison for details about the meaning of a row-wise comparison.

ISBN 9781906966041 | The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference | See the print edition |