Patch from Pavel Stehule, minor fixups by myself.
+
+
The ordinary comparison operators yield null (signifying unknown>)
when either input is null. Another way to do comparisons is with the
IS DISTINCT FROM construct:
expression IS DISTINCT FROM expression
+expression IS NOT DISTINCT FROM expression
- For non-null inputs this is the same as the <>> operator.
- However, when both inputs are null it will return false, and when just
- one input is null it will return true. Thus it effectively acts as though
- null were a normal data value, rather than unknown>.
+ For non-null inputs, IS DISTINCT FROM this is
+ the same as the <>> operator. However, when both
+ inputs are null it will return false, and when just one input is
+ null it will return true. Similarly, IS NOT DISTINCT
+ FROM is identical to = for non-null
+ inputs, returns true when both inputs are null, and false
+ otherwise. Thus, these constructs effectively act as though null
+ were a normal data value, rather than unknown>.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.516 2005/11/28 04:35:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.517 2005/12/11 10:54:27 neilc Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
{
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
}
+ | a_expr IS NOT DISTINCT FROM a_expr %prec IS
+ {
+ $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL, NULL,
+ (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
+ "=", $1, $6));
+
+ }
| a_expr IS OF '(' type_list ')' %prec IS
{
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
{
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5);
}
+ | b_expr IS NOT DISTINCT FROM b_expr %prec IS
+ {
+ $$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
+ NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $6));
+ }
| b_expr IS OF '(' type_list ')' %prec IS
{
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF, "=", $1, (Node *) $5);
f
(1 row)
+-- ANSI SQL 2003 form
+SELECT 1 IS NOT DISTINCT FROM 2 as "no";
+ no
+----
+ f
+(1 row)
+
+SELECT 2 IS NOT DISTINCT FROM 2 as "yes";
+ yes
+-----
+ t
+(1 row)
+
+SELECT 2 IS NOT DISTINCT FROM null as "no";
+ no
+----
+ f
+(1 row)
+
+SELECT null IS NOT DISTINCT FROM null as "yes";
+ yes
+-----
+ t
+(1 row)
+
SELECT 2 IS DISTINCT FROM 2 as "no";
SELECT 2 IS DISTINCT FROM null as "yes";
SELECT null IS DISTINCT FROM null as "no";
+
+-- ANSI SQL 2003 form
+SELECT 1 IS NOT DISTINCT FROM 2 as "no";
+SELECT 2 IS NOT DISTINCT FROM 2 as "yes";
+SELECT 2 IS NOT DISTINCT FROM null as "no";
+SELECT null IS NOT DISTINCT FROM null as "yes";