|
1 |
| -<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.48 2001/01/20 20:59:28 petere Exp $ --> |
| 1 | +<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.49 2001/01/21 22:02:01 petere Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="functions">
|
4 | 4 | <title>Functions and Operators</title>
|
|
24 | 24 | other implementations.
|
25 | 25 | </para>
|
26 | 26 |
|
| 27 | + |
| 28 | + <sect1 id="functions-logical"> |
| 29 | + <title>Logical Operators</title> |
| 30 | + |
| 31 | + <para> |
| 32 | + The usual logical operators are available: |
| 33 | + |
| 34 | + <simplelist> |
| 35 | + <member>AND</member> |
| 36 | + <member>OR</member> |
| 37 | + <member>NOT</member> |
| 38 | + </simplelist> |
| 39 | + |
| 40 | + SQL uses a three-valued boolean logic where NULL represents |
| 41 | + <quote>unknown</quote>. Observe the following truth tables: |
| 42 | + |
| 43 | + <informaltable> |
| 44 | + <tgroup cols="4"> |
| 45 | + <thead> |
| 46 | + <row> |
| 47 | + <entry><replaceable>a</replaceable></entry> |
| 48 | + <entry><replaceable>b</replaceable></entry> |
| 49 | + <entry><replaceable>a</replaceable> AND <replaceable>b</replaceable></entry> |
| 50 | + <entry><replaceable>a</replaceable> OR <replaceable>b</replaceable></entry> |
| 51 | + </row> |
| 52 | + </thead> |
| 53 | + |
| 54 | + <tbody> |
| 55 | + <row> |
| 56 | + <entry>TRUE</entry> |
| 57 | + <entry>TRUE</entry> |
| 58 | + <entry>TRUE</entry> |
| 59 | + <entry>TRUE</entry> |
| 60 | + </row> |
| 61 | + |
| 62 | + <row> |
| 63 | + <entry>TRUE</entry> |
| 64 | + <entry>FALSE</entry> |
| 65 | + <entry>FALSE</entry> |
| 66 | + <entry>TRUE</entry> |
| 67 | + </row> |
| 68 | + |
| 69 | + <row> |
| 70 | + <entry>TRUE</entry> |
| 71 | + <entry>NULL</entry> |
| 72 | + <entry>NULL</entry> |
| 73 | + <entry>TRUE</entry> |
| 74 | + </row> |
| 75 | + |
| 76 | + <row> |
| 77 | + <entry>FALSE</entry> |
| 78 | + <entry>FALSE</entry> |
| 79 | + <entry>FALSE</entry> |
| 80 | + <entry>FALSE</entry> |
| 81 | + </row> |
| 82 | + |
| 83 | + <row> |
| 84 | + <entry>FALSE</entry> |
| 85 | + <entry>NULL</entry> |
| 86 | + <entry>FALSE</entry> |
| 87 | + <entry>NULL</entry> |
| 88 | + </row> |
| 89 | + </tbody> |
| 90 | + </tgroup> |
| 91 | + </informaltable> |
| 92 | + |
| 93 | + <informaltable> |
| 94 | + <tgroup cols="2"> |
| 95 | + <thead> |
| 96 | + <row> |
| 97 | + <entry><replaceable>a</replaceable></entry> |
| 98 | + <entry>NOT <replaceable>a</replaceable></entry> |
| 99 | + </row> |
| 100 | + </thead> |
| 101 | + |
| 102 | + <tbody> |
| 103 | + <row> |
| 104 | + <entry>TRUE</entry> |
| 105 | + <entry>FALSE</entry> |
| 106 | + </row> |
| 107 | + |
| 108 | + <row> |
| 109 | + <entry>FALSE</entry> |
| 110 | + <entry>TRUE</entry> |
| 111 | + </row> |
| 112 | + |
| 113 | + <row> |
| 114 | + <entry>NULL</entry> |
| 115 | + <entry>NULL</entry> |
| 116 | + </row> |
| 117 | + </tbody> |
| 118 | + </tgroup> |
| 119 | + </informaltable> |
| 120 | + </para> |
| 121 | + </sect1> |
| 122 | + |
27 | 123 | <sect1 id="functions-comparison">
|
28 | 124 | <title>Comparison Operators</title>
|
29 | 125 |
|
|
88 | 184 | <literal><</literal> operator to compare a boolean with
|
89 | 185 | <literal>3</literal>).
|
90 | 186 | </para>
|
| 187 | + |
| 188 | + <para> |
| 189 | + To check whether a value is or is not NULL, use the constructs |
| 190 | +<synopsis> |
| 191 | +<replaceable>expression</replaceable> IS NULL |
| 192 | +<replaceable>expression</replaceable> IS NOT NULL |
| 193 | +</synopsis> |
| 194 | + Do <emphasis>not</emphasis> use |
| 195 | + <literal><replaceable>expression</replaceable> = NULL</literal> |
| 196 | + because NULL is not <quote>equal to</quote> NULL. (NULL represents |
| 197 | + an unknown value, so it is not known whether two unknown values are |
| 198 | + equal.) <productname>Postgres</productname> implicitly converts |
| 199 | + <literal>= NULL</literal> clauses to <literal>IS NULL</literal> to |
| 200 | + allow some broken client applications (such as |
| 201 | + <productname>Microsoft Access</productname>) to work, but this may |
| 202 | + be discontinued in a future release. |
| 203 | + </para> |
91 | 204 | </sect1>
|
92 | 205 |
|
93 | 206 |
|
|
0 commit comments