Month Day [ Hour : Minute : Second ] Year [AD,BC] [ Timezone ]
Month Day [ Hour : Minute : Second ] Year [AD,BC] [ Timezone ]
...
@@ -1003,62 +1013,65 @@ where
...
@@ -1003,62 +1013,65 @@ where
Minute is 00, 01, ..., 59
Minute is 00, 01, ..., 59
Second is 00, 01, ..., 59 (60 for leap second)
Second is 00, 01, ..., 59 (60 for leap second)
Timezone is 3 characters or ISO offset to GMT
Timezone is 3 characters or ISO offset to GMT
</ProgramListing>
</programlisting>
</para>
<Para>
<para>
Valid dates are from Nov 13 00:00:00 4013 BC GMT to far into the future.
Valid dates are from Nov 13 00:00:00 4013 BC GMT to far into the future.
Timezones are either three characters (e.g. "GMT" or "PST") or ISO-compatible
Timezones are either three characters (e.g. "GMT" or "PST") or ISO-compatible
offsets to GMT (e.g. "-08" or "-08:00" when in Pacific Standard Time).
offsets to GMT (e.g. "-08" or "-08:00" when in Pacific Standard Time).
Dates are stored internally in Greenwich Mean Time. Input and output routines
Dates are stored internally in Greenwich Mean Time. Input and output routines
translate time to the local time zone of the server.
translate time to the local time zone of the server.
</Para>
</para></sect2>
<Sect2>
<sect2>
<Title><Type>timespan</Type></Title>
<title><type>timespan</type></title>
<Para>
<para>
General-use time span is input using a wide range of
General-use time span is input using a wide range of
syntaxes, including ISO-compatible, <acronym>SQL</acronym>-compatible,
syntaxes, including ISO-compatible, <acronym>SQL</acronym>-compatible,
traditional
traditional
<ProductName>Postgres</ProductName> (see section on "relative time")
<productname>Postgres</productname> (see section on "relative time")
and other permutations of time span. Output formats can be ISO-compatible,
and other permutations of time span. Output formats can be ISO-compatible,
<acronym>SQL</acronym>-compatible, or traditional
<acronym>SQL</acronym>-compatible, or traditional
<ProductName>Postgres</ProductName>,
<productname>Postgres</productname>,
with the default set to be <ProductName>Postgres</ProductName>-compatible.
with the default set to be <productname>Postgres</productname>-compatible.
Months and years are a "qualitative" time interval, and are stored separately
Months and years are a "qualitative" time interval, and are stored separately
from the other "quantitative" time intervals such as day or hour.
from the other "quantitative" time intervals such as day or hour.
For date arithmetic,
For date arithmetic,
the qualitative time units are instantiated in the context of the
the qualitative time units are instantiated in the context of the
relevant date or time.
relevant date or time.
</para>
<Para>
<para>
Time span is specified with the following syntax:
Time span is specified with the following syntax:
<ProgramListing>
<programlisting>
Quantity Unit [Quantity Unit...] [Direction]
Quantity Unit [Quantity Unit...] [Direction]
@ Quantity Unit [Direction]
@ Quantity Unit [Direction]
where
where
Quantity is ..., `-1', `0', `1', `2', ...
Quantity is ..., <literal>-1</literal>, <literal>0</literal>, <literal>1</literal>, <literal>2</literal>, ...
Unit is `second', `minute', `hour', `day', `week', `month', `year',
Unit is <literal>second</literal>, <literal>minute</literal>, <literal>hour</literal>, <literal>day</literal>, <literal>week</literal>, <literal>month</literal>, <literal>year</literal>,
'decade', 'century', millenium', or abbreviations or plurals of these units.
<literal>decade</literal>, <literal>century</literal>, <literal>millenium</literal>, or abbreviations or plurals of these units.
Direction is `ago'.
Direction is <literal>ago</literal>.
</ProgramListing>
</programlisting>
</Para>
</para>
</Sect2>
</sect2>
<Sect2>
<sect2>
<Title>abstime</Title>
<title>abstime</title>
<Para>
<para>
Absolute time (<type>abstime</type>) is a limited-range (+/- 68 years) and
Absolute time (<type>abstime</type>) is a limited-range (+/- 68 years) and
limited-precision (1 sec)
limited-precision (1 sec)
date data type. <Type>datetime</Type> may be preferred, since it
date data type. <type>datetime</type> may be preferred, since it
covers a larger range with greater precision.
covers a larger range with greater precision.
</para>
<Para>
<para>
Absolute time is specified using the following syntax:
Absolute time is specified using the following syntax:
<ProgramListing>
<programlisting>
Month Day [ Hour : Minute : Second ] Year [ Timezone ]
Month Day [ Hour : Minute : Second ] Year [ Timezone ]
where
where
Month is Jan, Feb, ..., Dec
Month is Jan, Feb, ..., Dec
...
@@ -1067,311 +1080,315 @@ where
...
@@ -1067,311 +1080,315 @@ where
Minute is 00, 01, ..., 59
Minute is 00, 01, ..., 59
Second is 00, 01, ..., 59
Second is 00, 01, ..., 59
Year is 1901, 1902, ..., 2038
Year is 1901, 1902, ..., 2038
</ProgramListing>
</programlisting>
</Para>
</para>
<Para>
<para>
Valid dates are from Dec 13 20:45:53 1901 GMT to Jan 19 03:14:04
Valid dates are from <literal>Dec 13 20:45:53 1901 GMT</literal>
2038 GMT.
to <literal>Jan 19 03:14:04 2038 GMT</literal>.
<note>
<note>
<title>Historical Note</title>
<title>Historical Note</title>
<para>
<para>
As of Version 3.0, times are no longer read and written
As of Version 3.0, times are no longer read and written
using Greenwich Mean Time; the input and output routines default to
using Greenwich Mean Time; the input and output routines default to
the local time zone.
the local time zone.</para>
</note>
</note>
All special values allowed for <Type>datetime</Type> are also
All special values allowed for <type>datetime</type> are also
allowed for "absolute time".
allowed for "absolute time".
</Para>
</para>
</Sect2>
</sect2>
<Sect2>
<sect2>
<Title>reltime</Title>
<title>reltime</title>
<Para>
<para>
Relative time <Type>reltime</Type> is a limited-range (+/- 68 years)
Relative time <type>reltime</type> is a limited-range (+/- 68 years)
and limited-precision (1 sec) time span data type.
and limited-precision (1 sec) time span data type.
<Type>timespan</Type> should be preferred, since it
<type>timespan</type> should be preferred, since it
covers a larger range with greater precision and, more importantly,
covers a larger range with greater precision and, more importantly,
can distinguish between
can distinguish between
relative units (months and years) and quantitative units (days, hours, etc).
relative units (months and years) and quantitative units (days, hours, etc).
Instead, reltime
Instead, reltime
must force months to be exactly 30 days, so time arithmetic does not
must force months to be exactly 30 days, so time arithmetic does not
always work as expected.
always work as expected.
For example, adding one reltime year to abstime today does not
For example, adding one reltime <literal>year</literal> to abstime <literal>today</literal> does not
produce today's date one year from
produce today's date one year from
now, but rather a date 360 days from today.
now, but rather a date 360 days from today.
</Para>
</para>
<Para>
<para>
<Type>reltime</Type> shares input and output routines with the other
<type>reltime</type> shares input and output routines with the other
time span types.
time span types.
The section on <Type>timespan</Type> covers this in more detail.
The section on <type>timespan</type> covers this in more detail.
</Para>
</para>
</Sect2>
</sect2>
<Sect2>
<sect2>
<Title><Type>timestamp</Type></Title>
<title><type>timestamp</type></title>
<Para>
<para>
This is currently a limited-range absolute time which closely resembles the
This is currently a limited-range absolute time which closely resembles the
abstime
abstime
data type. It shares the general input parser with the other date/time types.
data type. It shares the general input parser with the other date/time types.
In future releases this type will absorb the capabilities of the
In future releases this type will absorb the capabilities of the
<Type>datetime</Type> type
<type>datetime</type> type
and will move toward <acronym>SQL92</acronym> compliance.
and will move toward <acronym>SQL92</acronym> compliance.
</Para>
</para>
<Para>
<para>
<Type>timestamp</Type> is specified using the same syntax as for
<type>timestamp</type> is specified using the same syntax as for
<Type>datetime</Type>.
<type>datetime</type>.
</Para>
</para>
</Sect2>
</sect2>
<Sect2>
<sect2>
<Title><Type>interval</Type></Title>
<title><type>interval</type></title>
<Para>
<para>
<Type>interval</Type> is an <Acronym>SQL92</Acronym> data type which is
<type>interval</type> is an <acronym>SQL92</acronym> data type which is
currently mapped to the <Type>timespan</Type>
currently mapped to the <type>timespan</type>
<ProductName>Postgres</ProductName> data type.
<productname>Postgres</productname> data type.
</Para>
</para>
</Sect2>
</sect2>
<Sect2>
<sect2>
<Title>tinterval</Title>
<title>tinterval</title>
<Para>
<para>
Time ranges are specified as:
Time ranges are specified as:
<ProgramListing>
<programlisting>
[ 'abstime' 'abstime']
[ 'abstime' 'abstime']
where
where
abstime is a time in the absolute time format.
abstime is a time in the absolute time format.
</ProgramListing>
</programlisting>
Special abstime values such as
Special abstime values such as
`current', `infinity' and `-infinity' can be used.
<literal>current', <literal>infinity' and <literal>-infinity' can be used.</literal></literal></literal>
</Para>
</para></sect2>
</Sect1>
</sect1>
<Sect1>
<sect1>
<Title>Boolean Type</Title>
<title>Boolean Type</title>
<Para>
<para>
<ProductName>Postgres</ProductName> supports <Type>bool</Type> as
<productname>Postgres</productname> supports <type>bool</type> as
the <Acronym>SQL3</Acronym> boolean type.
the <acronym>SQL3</acronym> boolean type.
<Type>bool</Type> can have one of only two states: 'true' or 'false'.
<type>bool</type> can have one of only two states: 'true' or 'false'.
A third state, 'unknown', is not
A third state, 'unknown', is not
implemented and is not suggested in <Acronym>SQL3</Acronym>;
implemented and is not suggested in <acronym>SQL3</acronym>;
<Acronym>NULL</Acronym> is an
<acronym>NULL</acronym> is an
effective substitute. <Type>bool</Type> can be used in any boolean expression,
effective substitute. <type>bool</type> can be used in any boolean expression,
and boolean expressions
and boolean expressions
always evaluate to a result compatible with this type.
always evaluate to a result compatible with this type.</para>