@@ -2885,37 +2885,36 @@ SELECT EXTRACT(days from '80 hours'::interval);
2885
2885
</table>
2886
2886
2887
2887
<para>
2888
- Valid literal values for the <quote>true</quote> state are:
2888
+ Boolean constants can be represented in SQL queries by the SQL
2889
+ key words <literal>TRUE</literal>, <literal>FALSE</literal>,
2890
+ and <literal>NULL</literal>.
2891
+ </para>
2892
+
2893
+ <para>
2894
+ The datatype input function for type <type>boolean</type> accepts these
2895
+ string representations for the <quote>true</quote> state:
2889
2896
<simplelist>
2890
- <member><literal>TRUE</literal></member>
2891
- <member><literal>'t'</literal></member>
2892
- <member><literal>'true'</literal></member>
2893
- <member><literal>'y'</literal></member>
2894
- <member><literal>'yes'</literal></member>
2895
- <member><literal>'on'</literal></member>
2896
- <member><literal>'1'</literal></member>
2897
+ <member><literal>true</literal></member>
2898
+ <member><literal>yes</literal></member>
2899
+ <member><literal>on</literal></member>
2900
+ <member><literal>1</literal></member>
2897
2901
</simplelist>
2898
- For the <quote>false</quote> state, the following values can be
2899
- used:
2902
+ and these representations for the <quote>false</quote> state:
2900
2903
<simplelist>
2901
- <member><literal>FALSE</literal></member>
2902
- <member><literal>'f'</literal></member>
2903
- <member><literal>'false'</literal></member>
2904
- <member><literal>'n'</literal></member>
2905
- <member><literal>'no'</literal></member>
2906
- <member><literal>'off'</literal></member>
2907
- <member><literal>'0'</literal></member>
2904
+ <member><literal>false</literal></member>
2905
+ <member><literal>no</literal></member>
2906
+ <member><literal>off</literal></member>
2907
+ <member><literal>0</literal></member>
2908
2908
</simplelist>
2909
+ Unique prefixes of these strings are also accepted, for
2910
+ example <literal>t</literal> or <literal>n</literal>.
2909
2911
Leading or trailing whitespace is ignored, and case does not matter.
2910
- The key words
2911
- <literal>TRUE</literal> and <literal>FALSE</literal> are the preferred
2912
- (<acronym>SQL</acronym>-compliant) usage.
2913
2912
</para>
2914
2913
2915
2914
<para>
2916
- <xref linkend=" datatype- boolean-example"> shows that
2917
- <type>boolean</type> values are output using the letters
2918
- <literal>t</literal> and <literal>f</literal >.
2915
+ The datatype output function for type <type> boolean</type> always emits
2916
+ either <literal>t</literal> or <literal>f</literal>, as shown in
2917
+ <xref linkend="datatype-boolean-example" >.
2919
2918
</para>
2920
2919
2921
2920
<example id="datatype-boolean-example">
@@ -2937,6 +2936,27 @@ SELECT * FROM test1 WHERE a;
2937
2936
t | sic est
2938
2937
</programlisting>
2939
2938
</example>
2939
+
2940
+ <para>
2941
+ The key words <literal>TRUE</literal> and <literal>FALSE</literal> are
2942
+ the preferred (<acronym>SQL</acronym>-compliant) method for writing
2943
+ Boolean constants in SQL queries. But you can also use the string
2944
+ representations by following the generic string-literal constant syntax
2945
+ described in <xref linkend="sql-syntax-constants-generic">, for
2946
+ example <literal>'yes'::boolean</literal>.
2947
+ </para>
2948
+
2949
+ <para>
2950
+ Note that the parser automatically understands
2951
+ that <literal>TRUE</literal> and <literal>FALSE</literal> are of
2952
+ type <type>boolean</type>, but this is not so
2953
+ for <literal>NULL</literal> because that can have any type.
2954
+ So in some contexts you might have to cast <literal>NULL</literal>
2955
+ to <type>boolean</type> explicitly, for
2956
+ example <literal>NULL::boolean</literal>. Conversely, the cast can be
2957
+ omitted from a string-literal Boolean value in contexts where the parser
2958
+ can deduce that the literal must be of type <type>boolean</type>.
2959
+ </para>
2940
2960
</sect1>
2941
2961
2942
2962
<sect1 id="datatype-enum">
0 commit comments