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

Commitafaa32d

Browse files
committed
Doc: improve description of allowed spellings for Boolean input.
datatype.sgml failed to explain that boolin() accepts any uniqueprefix of the basic input strings. Indeed it was actively misleadingbecause it called out a few minimal prefixes without mentioning thatthere were more valid inputs.I also felt that it wasn't doing anybody any favors by conflatingSQL key words, valid Boolean input, and string literals containingvalid Boolean input. Rewrite in hopes of reducing the confusion.Per bug #15836 from Yuming Wang, as diagnosed by David Johnston.Back-patch to supported branches.Discussion:https://postgr.es/m/15836-656fab055735f511@postgresql.org
1 parentf95d8f8 commitafaa32d

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,37 +2894,36 @@ SELECT EXTRACT(days from '80 hours'::interval);
28942894
</table>
28952895

28962896
<para>
2897-
Valid literal values for the <quote>true</quote> state are:
2897+
Boolean constants can be represented in SQL queries by the SQL
2898+
key words <literal>TRUE</literal>, <literal>FALSE</literal>,
2899+
and <literal>NULL</literal>.
2900+
</para>
2901+
2902+
<para>
2903+
The datatype input function for type <type>boolean</type> accepts these
2904+
string representations for the <quote>true</quote> state:
28982905
<simplelist>
2899-
<member><literal>TRUE</literal></member>
2900-
<member><literal>'t'</literal></member>
2901-
<member><literal>'true'</literal></member>
2902-
<member><literal>'y'</literal></member>
2903-
<member><literal>'yes'</literal></member>
2904-
<member><literal>'on'</literal></member>
2905-
<member><literal>'1'</literal></member>
2906+
<member><literal>true</literal></member>
2907+
<member><literal>yes</literal></member>
2908+
<member><literal>on</literal></member>
2909+
<member><literal>1</literal></member>
29062910
</simplelist>
2907-
For the <quote>false</quote> state, the following values can be
2908-
used:
2911+
and these representations for the <quote>false</quote> state:
29092912
<simplelist>
2910-
<member><literal>FALSE</literal></member>
2911-
<member><literal>'f'</literal></member>
2912-
<member><literal>'false'</literal></member>
2913-
<member><literal>'n'</literal></member>
2914-
<member><literal>'no'</literal></member>
2915-
<member><literal>'off'</literal></member>
2916-
<member><literal>'0'</literal></member>
2913+
<member><literal>false</literal></member>
2914+
<member><literal>no</literal></member>
2915+
<member><literal>off</literal></member>
2916+
<member><literal>0</literal></member>
29172917
</simplelist>
2918+
Unique prefixes of these strings are also accepted, for
2919+
example <literal>t</literal> or <literal>n</literal>.
29182920
Leading or trailing whitespace is ignored, and case does not matter.
2919-
The key words
2920-
<literal>TRUE</literal> and <literal>FALSE</literal> are the preferred
2921-
(<acronym>SQL</acronym>-compliant) usage.
29222921
</para>
29232922

29242923
<para>
2925-
<xref linkend="datatype-boolean-example"/> shows that
2926-
<type>boolean</type> values are output using the letters
2927-
<literal>t</literal> and <literal>f</literal>.
2924+
Thedatatype output function for type <type>boolean</type> always emits
2925+
either <literal>t</literal> or <literal>f</literal>, as shown in
2926+
<xref linkend="datatype-boolean-example"/>.
29282927
</para>
29292928

29302929
<example id="datatype-boolean-example">
@@ -2946,6 +2945,27 @@ SELECT * FROM test1 WHERE a;
29462945
t | sic est
29472946
</programlisting>
29482947
</example>
2948+
2949+
<para>
2950+
The key words <literal>TRUE</literal> and <literal>FALSE</literal> are
2951+
the preferred (<acronym>SQL</acronym>-compliant) method for writing
2952+
Boolean constants in SQL queries. But you can also use the string
2953+
representations by following the generic string-literal constant syntax
2954+
described in <xref linkend="sql-syntax-constants-generic"/>, for
2955+
example <literal>'yes'::boolean</literal>.
2956+
</para>
2957+
2958+
<para>
2959+
Note that the parser automatically understands
2960+
that <literal>TRUE</literal> and <literal>FALSE</literal> are of
2961+
type <type>boolean</type>, but this is not so
2962+
for <literal>NULL</literal> because that can have any type.
2963+
So in some contexts you might have to cast <literal>NULL</literal>
2964+
to <type>boolean</type> explicitly, for
2965+
example <literal>NULL::boolean</literal>. Conversely, the cast can be
2966+
omitted from a string-literal Boolean value in contexts where the parser
2967+
can deduce that the literal must be of type <type>boolean</type>.
2968+
</para>
29492969
</sect1>
29502970

29512971
<sect1 id="datatype-enum">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp