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

Commit9729c93

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 parent4bfb79f commit9729c93

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
@@ -2905,37 +2905,36 @@ SELECT EXTRACT(days from '80 hours'::interval);
29052905
</table>
29062906

29072907
<para>
2908-
Valid literal values for the <quote>true</quote> state are:
2908+
Boolean constants can be represented in SQL queries by the SQL
2909+
key words <literal>TRUE</literal>, <literal>FALSE</literal>,
2910+
and <literal>NULL</literal>.
2911+
</para>
2912+
2913+
<para>
2914+
The datatype input function for type <type>boolean</type> accepts these
2915+
string representations for the <quote>true</quote> state:
29092916
<simplelist>
2910-
<member><literal>TRUE</literal></member>
2911-
<member><literal>'t'</literal></member>
2912-
<member><literal>'true'</literal></member>
2913-
<member><literal>'y'</literal></member>
2914-
<member><literal>'yes'</literal></member>
2915-
<member><literal>'on'</literal></member>
2916-
<member><literal>'1'</literal></member>
2917+
<member><literal>true</literal></member>
2918+
<member><literal>yes</literal></member>
2919+
<member><literal>on</literal></member>
2920+
<member><literal>1</literal></member>
29172921
</simplelist>
2918-
For the <quote>false</quote> state, the following values can be
2919-
used:
2922+
and these representations for the <quote>false</quote> state:
29202923
<simplelist>
2921-
<member><literal>FALSE</literal></member>
2922-
<member><literal>'f'</literal></member>
2923-
<member><literal>'false'</literal></member>
2924-
<member><literal>'n'</literal></member>
2925-
<member><literal>'no'</literal></member>
2926-
<member><literal>'off'</literal></member>
2927-
<member><literal>'0'</literal></member>
2924+
<member><literal>false</literal></member>
2925+
<member><literal>no</literal></member>
2926+
<member><literal>off</literal></member>
2927+
<member><literal>0</literal></member>
29282928
</simplelist>
2929+
Unique prefixes of these strings are also accepted, for
2930+
example <literal>t</literal> or <literal>n</literal>.
29292931
Leading or trailing whitespace is ignored, and case does not matter.
2930-
The key words
2931-
<literal>TRUE</literal> and <literal>FALSE</literal> are the preferred
2932-
(<acronym>SQL</acronym>-compliant) usage.
29332932
</para>
29342933

29352934
<para>
2936-
<xref linkend="datatype-boolean-example"/> shows that
2937-
<type>boolean</type> values are output using the letters
2938-
<literal>t</literal> and <literal>f</literal>.
2935+
Thedatatype output function for type <type>boolean</type> always emits
2936+
either <literal>t</literal> or <literal>f</literal>, as shown in
2937+
<xref linkend="datatype-boolean-example"/>.
29392938
</para>
29402939

29412940
<example id="datatype-boolean-example">
@@ -2957,6 +2956,27 @@ SELECT * FROM test1 WHERE a;
29572956
t | sic est
29582957
</programlisting>
29592958
</example>
2959+
2960+
<para>
2961+
The key words <literal>TRUE</literal> and <literal>FALSE</literal> are
2962+
the preferred (<acronym>SQL</acronym>-compliant) method for writing
2963+
Boolean constants in SQL queries. But you can also use the string
2964+
representations by following the generic string-literal constant syntax
2965+
described in <xref linkend="sql-syntax-constants-generic"/>, for
2966+
example <literal>'yes'::boolean</literal>.
2967+
</para>
2968+
2969+
<para>
2970+
Note that the parser automatically understands
2971+
that <literal>TRUE</literal> and <literal>FALSE</literal> are of
2972+
type <type>boolean</type>, but this is not so
2973+
for <literal>NULL</literal> because that can have any type.
2974+
So in some contexts you might have to cast <literal>NULL</literal>
2975+
to <type>boolean</type> explicitly, for
2976+
example <literal>NULL::boolean</literal>. Conversely, the cast can be
2977+
omitted from a string-literal Boolean value in contexts where the parser
2978+
can deduce that the literal must be of type <type>boolean</type>.
2979+
</para>
29602980
</sect1>
29612981

29622982
<sect1 id="datatype-enum">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp