Commit d42d31e7 authored by Peter Eisentraut's avatar Peter Eisentraut

Alter documentation of boolean type, add example. Someone figured that it

wasn't clear that the "boolean type" was actually called "boolean".  Add
tip about "casting" booleans using CASE.

Spell check whole file.
parent 41b46289
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.50 2001/02/14 19:37:26 petere Exp $
--> -->
<chapter id="datatype"> <chapter id="datatype">
...@@ -27,8 +27,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe ...@@ -27,8 +27,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe
<para> <para>
<table id="datatype-table"> <table id="datatype-table">
<title><productname>Postgres</productname> Data Types</title> <title>Data Types</title>
<titleabbrev>Data Types</titleabbrev>
<tgroup cols="3"> <tgroup cols="3">
<thead> <thead>
<row> <row>
...@@ -60,7 +59,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe ...@@ -60,7 +59,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe
<row> <row>
<entry><type>boolean</type></entry> <entry><type>boolean</type></entry>
<entry><type>bool</type></entry> <entry><type>bool</type></entry>
<entry>logical boolean (true/false)</entry> <entry>logical Boolean (true/false)</entry>
</row> </row>
<row> <row>
...@@ -265,12 +264,11 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe ...@@ -265,12 +264,11 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Numeric Types</title> <title>Numeric Types</title>
<titleabbrev>Numerics</titleabbrev>
<tgroup cols="4"> <tgroup cols="4">
<thead> <thead>
<row> <row>
<entry>Numeric Type</entry> <entry>Type Name</entry>
<entry>Storage</entry> <entry>Storage</entry>
<entry>Description</entry> <entry>Description</entry>
<entry>Range</entry> <entry>Range</entry>
...@@ -326,7 +324,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe ...@@ -326,7 +324,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.49 2001/02/10 18:02:35 pe
<row> <row>
<entry>serial</entry> <entry>serial</entry>
<entry>4 bytes</entry> <entry>4 bytes</entry>
<entry>Identifer or cross-reference</entry> <entry>Identifier or cross-reference</entry>
<entry>0 to +2147483647</entry> <entry>0 to +2147483647</entry>
</row> </row>
</tbody> </tbody>
...@@ -424,12 +422,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -424,12 +422,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Monetary Types</title> <title>Monetary Types</title>
<titleabbrev>Money</titleabbrev>
<tgroup cols="4"> <tgroup cols="4">
<thead> <thead>
<row> <row>
<entry>Monetary Type</entry> <entry>Type Name</entry>
<entry>Storage</entry> <entry>Storage</entry>
<entry>Description</entry> <entry>Description</entry>
<entry>Range</entry> <entry>Range</entry>
...@@ -470,12 +467,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -470,12 +467,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Character Types</title> <title>Character Types</title>
<titleabbrev>Characters</titleabbrev>
<tgroup cols="4"> <tgroup cols="4">
<thead> <thead>
<row> <row>
<entry>Character Type</entry> <entry>Type Name</entry>
<entry>Storage</entry> <entry>Storage</entry>
<entry>Recommendation</entry> <entry>Recommendation</entry>
<entry>Description</entry> <entry>Description</entry>
...@@ -530,12 +526,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -530,12 +526,11 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Specialty Character Type</title> <title>Specialty Character Type</title>
<titleabbrev>Specialty Characters</titleabbrev>
<tgroup cols="3"> <tgroup cols="3">
<thead> <thead>
<row> <row>
<entry>Character Type</entry> <entry>Type Name</entry>
<entry>Storage</entry> <entry>Storage</entry>
<entry>Description</entry> <entry>Description</entry>
</row> </row>
...@@ -568,8 +563,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -568,8 +563,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Date/Time Types</title> <title>Date/Time Types</title>
<titleabbrev>Date/Time</titleabbrev>
<tgroup cols="4"> <tgroup cols="4">
<thead> <thead>
<row> <row>
...@@ -588,7 +582,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -588,7 +582,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<entry>8 bytes</entry> <entry>8 bytes</entry>
<entry>4713 BC</entry> <entry>4713 BC</entry>
<entry>AD 1465001</entry> <entry>AD 1465001</entry>
<entry>1 microsec / 14 digits</entry> <entry>1 microsecond / 14 digits</entry>
</row> </row>
<row> <row>
<entry><type>timestamp [ with time zone ]</type></entry> <entry><type>timestamp [ with time zone ]</type></entry>
...@@ -596,7 +590,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -596,7 +590,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<entry>8 bytes</entry> <entry>8 bytes</entry>
<entry>1903 AD</entry> <entry>1903 AD</entry>
<entry>2037 AD</entry> <entry>2037 AD</entry>
<entry>1 microsec / 14 digits</entry> <entry>1 microsecond / 14 digits</entry>
</row> </row>
<row> <row>
<entry><type>interval</type></entry> <entry><type>interval</type></entry>
...@@ -690,8 +684,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -690,8 +684,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
The following are possible inputs for the <type>date</type> type. The following are possible inputs for the <type>date</type> type.
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Date Input</title> <title>Date Input</title>
<titleabbrev>Date Inputs</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -747,8 +740,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -747,8 +740,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Month Abbreviations</title> <title>Month Abbreviations</title>
<titleabbrev>Month Abbreviations</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -814,8 +806,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -814,8 +806,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Day of Week Abbreviations</title> <title>Day of the Week Abbreviations</title>
<titleabbrev>Day of Week Abbreviations</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -870,8 +861,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -870,8 +861,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
The following are valid <type>time</type> inputs. The following are valid <type>time</type> inputs.
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Time Input</title> <title>Time Input</title>
<titleabbrev>Time Inputs</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -940,9 +930,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl ...@@ -940,9 +930,7 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
as follows: as follows:
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Time With Time <title>Time With Time Zone Input</title>
Zone Input</title>
<titleabbrev>Time With Time Zone Inputs</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -1002,8 +990,7 @@ January 8 04:05:06 1999 PST ...@@ -1002,8 +990,7 @@ January 8 04:05:06 1999 PST
<para> <para>
<table tocentry="1" id="datatype-timezone-table"> <table tocentry="1" id="datatype-timezone-table">
<title><productname>Postgres</productname> Time Zone Input</title> <title>Time Zone Input</title>
<titleabbrev>Time Zone Inputs</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -1062,7 +1049,7 @@ January 8 04:05:06 1999 PST ...@@ -1062,7 +1049,7 @@ January 8 04:05:06 1999 PST
<para> <para>
The following <acronym>SQL</acronym>-compatible functions can be used as date or time The following <acronym>SQL</acronym>-compatible functions can be used as date or time
input for the corresponding datatype: <literal>CURRENT_DATE</literal>, input for the corresponding data type: <literal>CURRENT_DATE</literal>,
<literal>CURRENT_TIME</literal>, <literal>CURRENT_TIMESTAMP</literal>. <literal>CURRENT_TIME</literal>, <literal>CURRENT_TIMESTAMP</literal>.
</para> </para>
<para> <para>
...@@ -1070,8 +1057,7 @@ January 8 04:05:06 1999 PST ...@@ -1070,8 +1057,7 @@ January 8 04:05:06 1999 PST
convenience. convenience.
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Special Date/Time Constants</title> <title>Special Date/Time Constants</title>
<titleabbrev>Constants</titleabbrev>
<tgroup cols="2"> <tgroup cols="2">
<thead> <thead>
<row> <row>
...@@ -1120,7 +1106,7 @@ January 8 04:05:06 1999 PST ...@@ -1120,7 +1106,7 @@ January 8 04:05:06 1999 PST
</tgroup> </tgroup>
</table> </table>
<literal>'now'</literal> is resolved when the value is inserted, <literal>'current'</literal> <literal>'now'</literal> is resolved when the value is inserted, <literal>'current'</literal>
is resolved everytime the value is retrieved. So you probably want to use <literal>'now'</literal> is resolved every time the value is retrieved. So you probably want to use <literal>'now'</literal>
in most applications. (Of course you <emphasis>really</emphasis> want to use in most applications. (Of course you <emphasis>really</emphasis> want to use
<literal>CURRENT_TIMESTAMP</literal>, which is equivalent to <literal>'now'</literal>.) <literal>CURRENT_TIMESTAMP</literal>, which is equivalent to <literal>'now'</literal>.)
</para> </para>
...@@ -1139,8 +1125,7 @@ January 8 04:05:06 1999 PST ...@@ -1139,8 +1125,7 @@ January 8 04:05:06 1999 PST
The default is the <acronym>ISO</acronym> format. The default is the <acronym>ISO</acronym> format.
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Date/Time Output Styles</title> <title>Date/Time Output Styles</title>
<titleabbrev>Styles</titleabbrev>
<tgroup cols="3"> <tgroup cols="3">
<thead> <thead>
<row> <row>
...@@ -1182,12 +1167,11 @@ January 8 04:05:06 1999 PST ...@@ -1182,12 +1167,11 @@ January 8 04:05:06 1999 PST
<para> <para>
The <acronym>SQL</acronym> style has European and non-European (US) variants, The <acronym>SQL</acronym> style has European and non-European (US) variants,
which determines whether month follows day or vica versa. (See also above which determines whether month follows day or vice versa. (See also above
at Date/Time Input, how this setting affects interpretation of input values.) at Date/Time Input, how this setting affects interpretation of input values.)
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Date Order Conventions</title> <title>Date Order Conventions</title>
<titleabbrev>Date Order</titleabbrev>
<tgroup cols="3"> <tgroup cols="3">
<thead> <thead>
<row> <row>
...@@ -1360,7 +1344,7 @@ January 8 04:05:06 1999 PST ...@@ -1360,7 +1344,7 @@ January 8 04:05:06 1999 PST
<note> <note>
<para> <para>
If the compiler option USE_AUSTRALIAN_RULES is set If the compiler option USE_AUSTRALIAN_RULES is set
then <literal>EST</literal> refers to Australia Eastern Std Time, then <literal>EST</literal> refers to Australia Eastern Standard Time,
which has an offset of +10:00 hours from UTC. which has an offset of +10:00 hours from UTC.
</para> </para>
</note> </note>
...@@ -1381,7 +1365,7 @@ January 8 04:05:06 1999 PST ...@@ -1381,7 +1365,7 @@ January 8 04:05:06 1999 PST
<para> <para>
Date conventions before the 19th century make for interesting reading, Date conventions before the 19th century make for interesting reading,
but are not consistant enough to warrant coding into a date/time handler. but are not consistent enough to warrant coding into a date/time handler.
</para> </para>
</sect2> </sect2>
...@@ -1391,45 +1375,80 @@ January 8 04:05:06 1999 PST ...@@ -1391,45 +1375,80 @@ January 8 04:05:06 1999 PST
<title>Boolean Type</title> <title>Boolean Type</title>
<para> <para>
<productname>Postgres</productname> supports the <productname>Postgres</productname> provides the
<acronym>SQL99</acronym> <type>boolean</type> type. <acronym>SQL99</acronym> type <type>boolean</type>.
<type>boolean</type> can have one of only two states: 'true' or <type>boolean</type> can have one of only two states:
'false'. A third state, 'unknown', is represented by the SQL NULL <quote>true</quote> or <quote>false</quote>. A third state,
state. <type>boolean</type> can be used in any boolean expression, <quote>unknown</quote>, is represented by the
and boolean expressions always evaluate to a result compatible <acronym>SQL</acronym> NULL state.
with this type. </para>
<para>
Valid literal values for the <quote>true</quote> state are:
<simplelist>
<member><literal>TRUE</literal></member>
<member><literal>'t'</literal></member>
<member><literal>'true'</literal></member>
<member><literal>'y'</literal></member>
<member><literal>'yes'</literal></member>
<member><literal>'1'</literal></member>
</simplelist>
For the <quote>false</quote> state, the following values can be
used:
<simplelist>
<member><literal>FALSE</literal></member>
<member><literal>'f'</literal></member>
<member><literal>'false'</literal></member>
<member><literal>'n'</literal></member>
<member><literal>'no'</literal></member>
<member><literal>'0'</literal></member>
</simplelist>
Using the key words <literal>TRUE</literal> and
<literal>FALSE</literal> is preferred (and
<acronym>SQL</acronym>-compliant).
</para>
<example id="datatype-boolean-example">
<title>Using the <type>boolean</type> type</title>
<programlisting>
CREATE TABLE test1 (a boolean, b text);
INSERT INTO test1 VALUES (TRUE, 'sic est');
INSERT INTO test1 VALUES (FALSE, 'non est');
SELECT * FROM test1;
a | b
---+---------
t | sic est
f | non est
SELECT * FROM test1 WHERE a;
a | b
---+---------
t | sic est
</programlisting>
</example>
<para>
<xref linkend="datatype-boolean-example"> shows that
<type>boolean</type> values are output using the letters
<literal>t</literal> and <literal>f</literal>.
</para> </para>
<tip>
<para> <para>
<type>boolean</type> uses 1 byte of storage. Values of the <type>boolean</type> type cannot be cast directly
to other types (e.g., <literal>CAST
(<replaceable>boolval</replaceable> AS integer)</literal> does
not work). This can be accomplished using the
<literal>CASE</literal> expression: <literal>CASE WHEN
<replaceable>boolval</replaceable> THEN 'value if true' ELSE
'value if false' END</literal>. See also <xref
linkend="functions-conditional">.
</para> </para>
</tip>
<para> <para>
<table tocentry="1"> <type>boolean</type> uses 1 byte of storage.
<title><productname>Postgres</productname> Boolean Type</title>
<titleabbrev>Booleans</titleabbrev>
<tgroup cols="3">
<thead>
<row>
<entry>State</entry>
<entry>Input</entry>
<entry>Output</entry>
</row>
</thead>
<tbody>
<row>
<entry>True</entry>
<entry>TRUE, 't', 'true', 'y', 'yes', '1'</entry>
<entry><literal>t</literal></entry>
</row>
<row>
<entry>False</entry>
<entry>FALSE, 'f', 'false', 'n', 'no', '0'</entry>
<entry><literal>f</literal></entry>
</row>
</tbody>
</tgroup>
</table>
</para> </para>
</sect1> </sect1>
...@@ -1444,8 +1463,7 @@ January 8 04:05:06 1999 PST ...@@ -1444,8 +1463,7 @@ January 8 04:05:06 1999 PST
<para> <para>
<table tocentry="1"> <table tocentry="1">
<title><productname>Postgres</productname> Geometric Types</title> <title>Geometric Types</title>
<titleabbrev>Geometrics</titleabbrev>
<tgroup cols="4"> <tgroup cols="4">
<thead> <thead>
<row> <row>
...@@ -1578,7 +1596,7 @@ January 8 04:05:06 1999 PST ...@@ -1578,7 +1596,7 @@ January 8 04:05:06 1999 PST
<term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term> <term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term>
<listitem> <listitem>
<para> <para>
The endpoints of the line segment. The end points of the line segment.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1662,7 +1680,7 @@ January 8 04:05:06 1999 PST ...@@ -1662,7 +1680,7 @@ January 8 04:05:06 1999 PST
<term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term> <term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
<listitem> <listitem>
<para> <para>
Endpoints of the line segments comprising the path. End points of the line segments comprising the path.
A leading square bracket ("[") indicates an open path, while A leading square bracket ("[") indicates an open path, while
a leading parenthesis ("(") indicates a closed path. a leading parenthesis ("(") indicates a closed path.
</para> </para>
...@@ -1702,7 +1720,7 @@ January 8 04:05:06 1999 PST ...@@ -1702,7 +1720,7 @@ January 8 04:05:06 1999 PST
<term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term> <term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
<listitem> <listitem>
<para> <para>
Endpoints of the line segments comprising the boundary of the End points of the line segments comprising the boundary of the
polygon. polygon.
</para> </para>
</listitem> </listitem>
...@@ -1822,7 +1840,7 @@ January 8 04:05:06 1999 PST ...@@ -1822,7 +1840,7 @@ January 8 04:05:06 1999 PST
The <type>inet</type> type holds an IP host address, and The <type>inet</type> type holds an IP host address, and
optionally the identity of the subnet it is in, all in one field. optionally the identity of the subnet it is in, all in one field.
The subnet identity is represented by the number of bits in the The subnet identity is represented by the number of bits in the
network part of the address (the "netmask"). If the netmask is 32, network part of the address (the <quote>netmask</quote>). If the netmask is 32,
then the value does not indicate a subnet, only a single host. then the value does not indicate a subnet, only a single host.
Note that if you want to accept networks only, you should use the Note that if you want to accept networks only, you should use the
<type>cidr</type> type rather than <type>inet</type>. <type>cidr</type> type rather than <type>inet</type>.
...@@ -1989,7 +2007,7 @@ January 8 04:05:06 1999 PST ...@@ -1989,7 +2007,7 @@ January 8 04:05:06 1999 PST
<replaceable>x</replaceable> specifies the maximum length. <replaceable>x</replaceable> specifies the maximum length.
<type>BIT</type> type data is automatically padded with 0's on the <type>BIT</type> type data is automatically padded with 0's on the
right to the maximum length, <type>BIT VARYING</type> is of right to the maximum length, <type>BIT VARYING</type> is of
variable length. <type>BIT</type> without length is requivalent variable length. <type>BIT</type> without length is equivalent
to <literal>BIT(1)</literal>, <type>BIT VARYING</type> means to <literal>BIT(1)</literal>, <type>BIT VARYING</type> means
unlimited length. Input data that is longer than the allowed unlimited length. Input data that is longer than the allowed
length will be truncated. Refer to <xref length will be truncated. Refer to <xref
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment