+ linkend="functions-comparison-pred-table">. These behave much like
+ operators, but have special syntax mandated by the SQL standard.
+
+
+
+
Comparison Predicates
+
+
+ |
+ Predicate
+ Description
+
+
+
+
+ |
+ a> BETWEEN> x> AND> y>
+ between
+
+
+ |
+ a> NOT BETWEEN> x> AND> y>
+ not between
+
+
+ |
+ a> BETWEEN SYMMETRIC> x> AND> y>
+ between, after sorting the comparison values
+
+
+ |
+ a> NOT BETWEEN SYMMETRIC> x> AND> y>
+ not between, after sorting the comparison values
+
+
+ |
+ a> IS DISTINCT FROM> b>
+ not equal, treating null like an ordinary value
+
+
+ |
+ a> IS NOT DISTINCT FROM> b>
+ equal, treating null like an ordinary value
+
+
+ |
+ expression> IS NULL>
+ is null
+
+
+ |
+ expression> IS NOT NULL>
+ is not null
+
+
+ |
+ expression> ISNULL>
+ is null (nonstandard syntax)
+
+
+ |
+ expression> NOTNULL>
+ is not null (nonstandard syntax)
+
+
+ |
+ boolean_expression> IS TRUE>
+ is true
+
+
+ |
+ boolean_expression> IS NOT TRUE>
+ is false or unknown
+
+
+ |
+ boolean_expression> IS FALSE>
+ is false
+
+
+ |
+ boolean_expression> IS NOT FALSE>
+ is true or unknown
+
+
+ |
+ boolean_expression> IS UNKNOWN>
+ is unknown
+
+
+ |
+ boolean_expression> IS NOT UNKNOWN>
+ is true or false
+
+
+
+
+
- In addition to the comparison operators, the special
- BETWEEN construct is available:
+ The BETWEEN predicate simplifies range tests:
a BETWEEN x AND y
- BETWEEN SYMMETRIC> is the same as BETWEEN>
+ BETWEEN SYMMETRIC> is like BETWEEN>
except there is no requirement that the argument to the left of
AND> be less than or equal to the argument on the right.
If it is not, those two arguments are automatically swapped, so that
a nonempty range is always implied.
+
+
+
+
+ Ordinary comparison operators yield null (signifying unknown>),
+ not true or false, when either input is null. For example,
+ 7 = NULL> yields null, as does 7 <> NULL>. When
+ this behavior is not suitable, use the
+ IS NOT > DISTINCT FROM predicates:
+
+a IS DISTINCT FROM b
+a IS NOT DISTINCT FROM b
+
+ For non-null inputs, IS DISTINCT FROM is
+ the same as the <>> operator. However, if both
+ inputs are null it returns false, and if only one input is
+ null it returns true. Similarly, IS NOT DISTINCT
+ FROM is identical to = for non-null
+ inputs, but it returns true when both inputs are null, and false when only
+ one input is null. Thus, these predicates effectively act as though null
+ were a normal data value, rather than unknown>.
+
+
- To check whether a value is or is not null, use the constructs:
+ To check whether a value is or is not null, use the predicates:
expression IS NULL
expression IS NOT NULL
- or the equivalent, but nonstandard, constructs:
+ or the equivalent, but nonstandard, predicates:
expression ISNULL
expression NOTNULL
expression = NULL
because NULL> is not equal to
NULL>. (The null value represents an unknown value,
- and it is not known whether two unknown values are equal.) This
- behavior conforms to the SQL standard.
+ and it is not known whether two unknown values are equal.)
-
If the expression is row-valued, then
IS NULL> is true when the row expression itself is null
IS NOT NULL> is true when the row expression itself is non-null
and all the row's fields are non-null. Because of this behavior,
IS NULL> and IS NOT NULL> do not always return
- inverse results for row-valued expressions, i.e., a row-valued
- expression that contains both NULL and non-null values will return false
- for both tests.
- This definition conforms to the SQL standard, and is a change from the
- inconsistent behavior exhibited by
PostgreSQL
- versions prior to 8.2.
-
-
-
-
-
-
-
- Ordinary comparison operators yield null (signifying unknown>),
- not true or false, when either input is null. For example,
- 7 = NULL> yields null, as does 7 <> NULL>. When
- this behavior is not suitable, use the
- IS NOT > DISTINCT FROM constructs:
-
-expression IS DISTINCT FROM expression
-expression IS NOT DISTINCT FROM expression
-
- For non-null inputs, IS DISTINCT FROM is
- the same as the <>> operator. However, if both
- inputs are null it returns false, and if only one input is
- null it returns true. Similarly, IS NOT DISTINCT
- FROM is identical to = for non-null
- inputs, but it returns true when both inputs are null, and false when only
- one input is null. Thus, these constructs effectively act as though null
- were a normal data value, rather than unknown>.
+ inverse results for row-valued expressions; in particular, a row-valued
+ expression that contains both null and non-null fields will return false
+ for both tests. In some cases, it may be preferable to
+ write row IS DISTINCT FROM NULL>
+ or row IS NOT DISTINCT FROM NULL>,
+ which will simply check whether the overall row value is null without any
+ additional tests on the row fields.
- Boolean values can also be tested using the constructs
+ Boolean values can also be tested using the predicates
-expression IS TRUE
-expression IS NOT TRUE
-expression IS FALSE
-expression IS NOT FALSE
-expression IS UNKNOWN
-expression IS NOT UNKNOWN
+boolean_expression IS TRUE
+boolean_expression IS NOT TRUE
+boolean_expression IS FALSE
+boolean_expression IS NOT FALSE
+boolean_expression IS UNKNOWN
+boolean_expression IS NOT UNKNOWN
These will always return true or false, never a null value, even when the
operand is null.
It is possible to check the data type of an expression using the
- constructs
+ predicates
expression IS OF (typename, ...)
expression IS NOT OF (typename, ...)
num_nonnulls(VARIADIC "any")
- returns the number of non-NULL arguments
+ returns the number of non-null arguments
num_nonnulls(1, NULL, 2)
2
num_nulls(VARIADIC "any")
- returns the number of NULL arguments
+ returns the number of null arguments
num_nulls(1, NULL, 2)
1