|
289 | 289 | a nonempty range is always implied.
|
290 | 290 | </para>
|
291 | 291 |
|
| 292 | + <para> |
| 293 | + <indexterm> |
| 294 | + <primary>IS DISTINCT FROM</primary> |
| 295 | + </indexterm> |
| 296 | + <indexterm> |
| 297 | + <primary>IS NOT DISTINCT FROM</primary> |
| 298 | + </indexterm> |
| 299 | + Ordinary comparison operators yield null (signifying <quote>unknown</>), |
| 300 | + not true or false, when either input is null. For example, |
| 301 | + <literal>7 = NULL</> yields null, as does <literal>7 <> NULL</>. When |
| 302 | + this behavior is not suitable, use the |
| 303 | + <literal>IS <optional> NOT </> DISTINCT FROM</literal> constructs: |
| 304 | +<synopsis> |
| 305 | +<replaceable>a</replaceable> IS DISTINCT FROM <replaceable>b</replaceable> |
| 306 | +<replaceable>a</replaceable> IS NOT DISTINCT FROM <replaceable>b</replaceable> |
| 307 | +</synopsis> |
| 308 | + For non-null inputs, <literal>IS DISTINCT FROM</literal> is |
| 309 | + the same as the <literal><></> operator. However, if both |
| 310 | + inputs are null it returns false, and if only one input is |
| 311 | + null it returns true. Similarly, <literal>IS NOT DISTINCT |
| 312 | + FROM</literal> is identical to <literal>=</literal> for non-null |
| 313 | + inputs, but it returns true when both inputs are null, and false when only |
| 314 | + one input is null. Thus, these constructs effectively act as though null |
| 315 | + were a normal data value, rather than <quote>unknown</>. |
| 316 | + </para> |
| 317 | + |
292 | 318 | <para>
|
293 | 319 | <indexterm>
|
294 | 320 | <primary>IS NULL</primary>
|
|
320 | 346 | <literal><replaceable>expression</replaceable> = NULL</literal>
|
321 | 347 | because <literal>NULL</> is not <quote>equal to</quote>
|
322 | 348 | <literal>NULL</>. (The null value represents an unknown value,
|
323 |
| - and it is not known whether two unknown values are equal.) This |
324 |
| - behavior conforms to the SQL standard. |
| 349 | + and it is not known whether two unknown values are equal.) |
325 | 350 | </para>
|
326 | 351 |
|
327 | 352 | <tip>
|
|
338 | 363 | </para>
|
339 | 364 | </tip>
|
340 | 365 |
|
341 |
| - <note> |
342 | 366 | <para>
|
343 | 367 | If the <replaceable>expression</replaceable> is row-valued, then
|
344 | 368 | <literal>IS NULL</> is true when the row expression itself is null
|
345 | 369 | or when all the row's fields are null, while
|
346 | 370 | <literal>IS NOT NULL</> is true when the row expression itself is non-null
|
347 | 371 | and all the row's fields are non-null. Because of this behavior,
|
348 | 372 | <literal>IS NULL</> and <literal>IS NOT NULL</> do not always return
|
349 |
| - inverse results for row-valued expressions, i.e., a row-valued |
350 |
| - expression that contains both NULL and non-null values will return false |
351 |
| - for both tests. |
352 |
| - This definition conforms to the SQL standard, and is a change from the |
353 |
| - inconsistent behavior exhibited by <productname>PostgreSQL</productname> |
354 |
| - versions prior to 8.2. |
355 |
| - </para> |
356 |
| - </note> |
357 |
| - |
358 |
| - <para> |
359 |
| - <indexterm> |
360 |
| - <primary>IS DISTINCT FROM</primary> |
361 |
| - </indexterm> |
362 |
| - <indexterm> |
363 |
| - <primary>IS NOT DISTINCT FROM</primary> |
364 |
| - </indexterm> |
365 |
| - Ordinary comparison operators yield null (signifying <quote>unknown</>), |
366 |
| - not true or false, when either input is null. For example, |
367 |
| - <literal>7 = NULL</> yields null, as does <literal>7 <> NULL</>. When |
368 |
| - this behavior is not suitable, use the |
369 |
| - <literal>IS <optional> NOT </> DISTINCT FROM</literal> constructs: |
370 |
| -<synopsis> |
371 |
| -<replaceable>expression</replaceable> IS DISTINCT FROM <replaceable>expression</replaceable> |
372 |
| -<replaceable>expression</replaceable> IS NOT DISTINCT FROM <replaceable>expression</replaceable> |
373 |
| -</synopsis> |
374 |
| - For non-null inputs, <literal>IS DISTINCT FROM</literal> is |
375 |
| - the same as the <literal><></> operator. However, if both |
376 |
| - inputs are null it returns false, and if only one input is |
377 |
| - null it returns true. Similarly, <literal>IS NOT DISTINCT |
378 |
| - FROM</literal> is identical to <literal>=</literal> for non-null |
379 |
| - inputs, but it returns true when both inputs are null, and false when only |
380 |
| - one input is null. Thus, these constructs effectively act as though null |
381 |
| - were a normal data value, rather than <quote>unknown</>. |
| 373 | + inverse results for row-valued expressions; in particular, a row-valued |
| 374 | + expression that contains both null and non-null fields will return false |
| 375 | + for both tests. In some cases, it may be preferable to |
| 376 | + write <replaceable>row</replaceable> <literal>IS DISTINCT FROM NULL</> |
| 377 | + or <replaceable>row</replaceable> <literal>IS NOT DISTINCT FROM NULL</>, |
| 378 | + which will simply check whether the overall row value is null without any |
| 379 | + additional tests on the row fields. |
382 | 380 | </para>
|
383 | 381 |
|
384 | 382 | <para>
|
|
0 commit comments