Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe8100d

Browse files
author
Neil Conway
committed
Implement IS NOT DISTINCT FROM, update the regression tests and docs.
Patch from Pavel Stehule, minor fixups by myself.
1 parentc105931 commitbe8100d

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.297 2005/12/03 16:45:05 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.298 2005/12/11 10:54:27 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -345,16 +345,24 @@ PostgreSQL documentation
345345
<indexterm>
346346
<primary>IS DISTINCT FROM</primary>
347347
</indexterm>
348+
<indexterm>
349+
<primary>IS NOT DISTINCT FROM</primary>
350+
</indexterm>
348351
The ordinary comparison operators yield null (signifying <quote>unknown</>)
349352
when either input is null. Another way to do comparisons is with the
350353
<literal>IS DISTINCT FROM</literal> construct:
351354
<synopsis>
352355
<replaceable>expression</replaceable> IS DISTINCT FROM <replaceable>expression</replaceable>
356+
<replaceable>expression</replaceable> IS NOT DISTINCT FROM <replaceable>expression</replaceable>
353357
</synopsis>
354-
For non-null inputs this is the same as the <literal>&lt;&gt;</> operator.
355-
However, when both inputs are null it will return false, and when just
356-
one input is null it will return true. Thus it effectively acts as though
357-
null were a normal data value, rather than <quote>unknown</>.
358+
For non-null inputs, <literal>IS DISTINCT FROM</literal> this is
359+
the same as the <literal>&lt;&gt;</> operator. However, when both
360+
inputs are null it will return false, and when just one input is
361+
null it will return true. Similarly, <literal>IS NOT DISTINCT
362+
FROM</literal> is identical to <literal>=</literal> for non-null
363+
inputs, returns true when both inputs are null, and false
364+
otherwise. Thus, these constructs effectively act as though null
365+
were a normal data value, rather than <quote>unknown</>.
358366
</para>
359367

360368
<para>

‎src/backend/parser/gram.y

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.516 2005/11/28 04:35:31 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.517 2005/12/11 10:54:27 neilc Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -6715,6 +6715,13 @@ a_expr:c_expr{ $$ = $1; }
67156715
{
67166716
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,"=",$1,$5);
67176717
}
6718+
| a_expr IS NOT DISTINCT FROM a_expr%prec IS
6719+
{
6720+
$$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,NULL,
6721+
(Node *) makeSimpleA_Expr(AEXPR_DISTINCT,
6722+
"=",$1,$6));
6723+
6724+
}
67186725
| a_expr IS OF'(' type_list')'%prec IS
67196726
{
67206727
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF,"=",$1, (Node *)$5);
@@ -6880,6 +6887,11 @@ b_expr:c_expr
68806887
{
68816888
$$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,"=",$1,$5);
68826889
}
6890+
| b_expr IS NOT DISTINCT FROM b_expr%prec IS
6891+
{
6892+
$$ = (Node *) makeA_Expr(AEXPR_NOT, NIL,
6893+
NULL, (Node *) makeSimpleA_Expr(AEXPR_DISTINCT,"=",$1,$6));
6894+
}
68836895
| b_expr IS OF'(' type_list')'%prec IS
68846896
{
68856897
$$ = (Node *) makeSimpleA_Expr(AEXPR_OF,"=",$1, (Node *)$5);

‎src/test/regress/expected/select_distinct.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,28 @@ SELECT null IS DISTINCT FROM null as "no";
195195
f
196196
(1 row)
197197

198+
-- ANSI SQL 2003 form
199+
SELECT 1 IS NOT DISTINCT FROM 2 as "no";
200+
no
201+
----
202+
f
203+
(1 row)
204+
205+
SELECT 2 IS NOT DISTINCT FROM 2 as "yes";
206+
yes
207+
-----
208+
t
209+
(1 row)
210+
211+
SELECT 2 IS NOT DISTINCT FROM null as "no";
212+
no
213+
----
214+
f
215+
(1 row)
216+
217+
SELECT null IS NOT DISTINCT FROM null as "yes";
218+
yes
219+
-----
220+
t
221+
(1 row)
222+

‎src/test/regress/sql/select_distinct.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ SELECT 1 IS DISTINCT FROM 2 as "yes";
5656
SELECT2 IS DISTINCTFROM2as"no";
5757
SELECT2 IS DISTINCTFROMnullas"yes";
5858
SELECTnull IS DISTINCTFROMnullas"no";
59+
60+
-- ANSI SQL 2003 form
61+
SELECT1 IS NOT DISTINCTFROM2as"no";
62+
SELECT2 IS NOT DISTINCTFROM2as"yes";
63+
SELECT2 IS NOT DISTINCTFROMnullas"no";
64+
SELECTnull IS NOT DISTINCTFROMnullas"yes";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp