1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.108 2002/11/15 03:11:15 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.109 2002/11/21 23:31:20 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="datatype">
@@ -1569,19 +1569,31 @@ SELECT b, char_length(b) FROM test2;
1569
1569
<secondary>data type</secondary>
1570
1570
</indexterm>
1571
1571
1572
+ <indexterm>
1573
+ <primary>timestamp with time zone</primary>
1574
+ <secondary>data type</secondary>
1575
+ </indexterm>
1576
+
1572
1577
<indexterm>
1573
1578
<primary>timestamp without time zone</primary>
1574
1579
<secondary>data type</secondary>
1575
1580
</indexterm>
1576
1581
1577
1582
<para>
1578
- Time stamp types exist as <type>timestamp [
1579
- (<replaceable>p</replaceable>) ]</type>, <type>timestamp [
1583
+ The time stamp types are <type>timestamp [
1580
1584
(<replaceable>p</replaceable>) ] without time zone</type> and
1581
- <type>timestamp [ (<replaceable>p</replaceable>) ] without time
1582
- zone</type>. A plain <type>timestamp</type> is equivalent to
1583
- <type>timestamp without timezone</type>.
1585
+ <type>timestamp [ (<replaceable>p</replaceable>) ] with time
1586
+ zone</type>. Writing just <type>timestamp</type> is equivalent to
1587
+ <type>timestamp without time zone</type>.
1588
+ </para>
1589
+
1590
+ <note>
1591
+ <para>
1592
+ Prior to <productname>PostgreSQL</productname> 7.3, writing just
1593
+ <type>timestamp</type> was equivalent to <type>timestamp with time
1594
+ zone</type>. This was changed for SQL spec compliance.
1584
1595
</para>
1596
+ </note>
1585
1597
1586
1598
<para>
1587
1599
Valid input for the time stamp types consists of a concatenation
@@ -1615,11 +1627,38 @@ January 8 04:05:06 1999 PST
1615
1627
1616
1628
<para>
1617
1629
For <type>timestamp without time zone</type>, any explicit time
1618
- zone specified in the input is silently swallowed . That is, the
1630
+ zone specified in the input is silently ignored . That is, the
1619
1631
resulting date/time value is derived from the explicit date/time
1620
1632
fields in the input value, and is not adjusted for time zone.
1621
1633
</para>
1622
1634
1635
+ <para>
1636
+ For <type>timestamp with time zone</type>, the internally stored
1637
+ value is always in UTC (GMT). An input value that has an explicit
1638
+ time zone specified is converted to UTC using the appropriate offset
1639
+ for that time zone. If no time zone is stated in the input string,
1640
+ then it is assumed to be in the time zone indicated by the system's
1641
+ <varname>TimeZone</> parameter, and is converted to UTC using the
1642
+ offset for the <varname>TimeZone</> zone.
1643
+ </para>
1644
+
1645
+ <para>
1646
+ When a <type>timestamp with time
1647
+ zone</type> value is output, it is always converted from UTC to the
1648
+ current <varname>TimeZone</> zone, and displayed as local time in that
1649
+ zone. To see the time in another time zone, either change
1650
+ <varname>TimeZone</> or use the <literal>AT TIME ZONE</> construct
1651
+ (see <xref linkend="functions-datetime-zoneconvert">).
1652
+ </para>
1653
+
1654
+ <para>
1655
+ Conversions between <type>timestamp without time zone</type> and
1656
+ <type>timestamp with time zone</type> normally assume that the
1657
+ <type>timestamp without time zone</type> value should be taken or given
1658
+ as <varname>TimeZone</> local time. A different zone reference can
1659
+ be specified for the conversion using <literal>AT TIME ZONE</>.
1660
+ </para>
1661
+
1623
1662
<table tocentry="1" id="datatype-timezone-table">
1624
1663
<title>Time Zone Input</title>
1625
1664
<tgroup cols="2">
@@ -1707,24 +1746,28 @@ January 8 04:05:06 1999 PST
1707
1746
<para>
1708
1747
The following <acronym>SQL</acronym>-compatible functions can be
1709
1748
used as date or time
1710
- input for the corresponding data type: <literal>CURRENT_DATE</literal>,
1749
+ values for the corresponding data type: <literal>CURRENT_DATE</literal>,
1711
1750
<literal>CURRENT_TIME</literal>,
1712
1751
<literal>CURRENT_TIMESTAMP</literal>. The latter two accept an
1713
- optional precision specification. (See also <xref linkend="functions-datetime">.)
1752
+ optional precision specification. (See also <xref linkend="functions-datetime-current ">.)
1714
1753
</para>
1715
1754
1716
1755
<para>
1717
1756
<productname>PostgreSQL</productname> also supports several
1718
- special constants for convenience, shown in <xref
1719
- linkend="datatype-datetime-special-table">.
1757
+ special date/time input values for convenience, as shown in <xref
1758
+ linkend="datatype-datetime-special-table">. The values
1759
+ <literal>infinity</literal> and <literal>-infinity</literal>
1760
+ are specially represented inside the system and will be displayed
1761
+ the same way; but the others are simply notational shorthands
1762
+ that will be converted to ordinary date/time values when read.
1720
1763
</para>
1721
1764
1722
1765
<table id="datatype-datetime-special-table">
1723
- <title>Special Date/Time Constants </title>
1766
+ <title>Special Date/Time Inputs </title>
1724
1767
<tgroup cols="2">
1725
1768
<thead>
1726
1769
<row>
1727
- <entry>Constant </entry>
1770
+ <entry>Input string </entry>
1728
1771
<entry>Description</entry>
1729
1772
</row>
1730
1773
</thead>
@@ -1735,15 +1778,13 @@ January 8 04:05:06 1999 PST
1735
1778
</row>
1736
1779
<row>
1737
1780
<entry><literal>infinity</literal></entry>
1738
- <entry>later than other valid times</entry>
1781
+ <entry>later than all other timestamps (not available for
1782
+ type <type>date</>)</entry>
1739
1783
</row>
1740
1784
<row>
1741
1785
<entry><literal>-infinity</literal></entry>
1742
- <entry>earlier than other valid times</entry>
1743
- </row>
1744
- <row>
1745
- <entry><literal>invalid</literal></entry>
1746
- <entry>illegal entry</entry>
1786
+ <entry>earlier than all other timestamps (not available for
1787
+ type <type>date</>)</entry>
1747
1788
</row>
1748
1789
<row>
1749
1790
<entry><literal>now</literal></entry>
@@ -1962,13 +2003,21 @@ January 8 04:05:06 1999 PST
1962
2003
</para>
1963
2004
1964
2005
<para>
1965
- There are several ways to affect the time- zone behavior :
2006
+ There are several ways to select the time zone used by the server :
1966
2007
1967
2008
<itemizedlist>
1968
2009
<listitem>
1969
2010
<para>
1970
2011
The <envar>TZ</envar> environment variable on the server host
1971
- is used by the server as the default time zone.
2012
+ is used by the server as the default time zone, if no other is
2013
+ specified.
2014
+ </para>
2015
+ </listitem>
2016
+
2017
+ <listitem>
2018
+ <para>
2019
+ The <varname>timezone</varname> configuration parameter can be
2020
+ set in <filename>postgresql.conf</>.
1972
2021
</para>
1973
2022
</listitem>
1974
2023
@@ -1987,18 +2036,6 @@ January 8 04:05:06 1999 PST
1987
2036
sets the time zone for the session.
1988
2037
</para>
1989
2038
</listitem>
1990
-
1991
- <listitem>
1992
- <para>
1993
- The construct
1994
- <programlisting>
1995
- <replaceable>timestamp</replaceable> AT TIME ZONE '<replaceable>zone</replaceable>'
1996
- </programlisting>
1997
- where <replaceable>zone</replaceable> can be specified as a
1998
- text time zone (e.g., <literal>'PST'</literal>) or as an
1999
- interval (e.g., <literal>INTERVAL '-08:00'</literal>).
2000
- </para>
2001
- </listitem>
2002
2039
</itemizedlist>
2003
2040
</para>
2004
2041
0 commit comments