1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.120 2003/07/18 03:45:06 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.121 2003/07/29 00: 03:17 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="datatype">
@@ -1346,15 +1346,12 @@ SELECT b, char_length(b) FROM test2;
1346
1346
Date and time input is accepted in almost any reasonable format, including
1347
1347
ISO 8601, <acronym>SQL</acronym>-compatible,
1348
1348
traditional <productname>POSTGRES</productname>, and others.
1349
- For some formats, ordering of month and day in date input can be
1349
+ For some formats, ordering of month, day, and year in date input is
1350
1350
ambiguous and there is support for specifying the expected
1351
- ordering of these fields.
1352
- The command
1353
- <literal>SET datestyle TO 'US'</literal>
1354
- or <literal>SET datestyle TO 'NonEuropean'</literal>
1355
- specifies the variant <quote>month before day</quote>, the command
1356
- <literal>SET datestyle TO 'European'</literal> sets the variant
1357
- <quote>day before month</quote>.
1351
+ ordering of these fields. Set the <varname>datestyle</> parameter
1352
+ to <literal>MDY</> to select month-day-year interpretation,
1353
+ <literal>DMY</> to select day-month-year interpretation, or
1354
+ <literal>YMD</> to select year-month-day interpretation.
1358
1355
</para>
1359
1356
1360
1357
<para>
@@ -1410,36 +1407,42 @@ SELECT b, char_length(b) FROM test2;
1410
1407
<tbody>
1411
1408
<row>
1412
1409
<entry>January 8, 1999</entry>
1413
- <entry>unambiguous</entry>
1410
+ <entry>unambiguous in any datestyle input mode </entry>
1414
1411
</row>
1415
1412
<row>
1416
1413
<entry>1999-01-08</entry>
1417
- <entry>ISO-8601 format, preferred</entry>
1414
+ <entry>ISO-8601, January 8 in any mode
1415
+ (recommended format)</entry>
1418
1416
</row>
1419
1417
<row>
1420
1418
<entry>1/8/1999</entry>
1421
- <entry>ambiguous (January 8 in U.S. mode; August 1 in European mode)</entry>
1419
+ <entry>January 8 in <literal>MDY</> mode;
1420
+ August 1 in <literal>DMY</> mode</entry>
1422
1421
</row>
1423
1422
<row>
1424
1423
<entry>1/18/1999</entry>
1425
- <entry>U.S. notation; January 18 in any mode</entry>
1424
+ <entry>January 18 in <literal>MDY</> mode;
1425
+ rejected in other modes</entry>
1426
+ </row>
1427
+ <row>
1428
+ <entry>01/02/03</entry>
1429
+ <entry>January 2, 2003 in <literal>MDY</> mode;
1430
+ February 1, 2003 in <literal>DMY</> mode;
1431
+ February 3, 2001 in <literal>YMD</> mode
1432
+ </entry>
1426
1433
</row>
1427
1434
<row>
1428
1435
<entry>19990108</entry>
1429
- <entry>ISO-8601; year, month, day </entry>
1436
+ <entry>ISO-8601; January 8, 1999 in any mode </entry>
1430
1437
</row>
1431
1438
<row>
1432
1439
<entry>990108</entry>
1433
- <entry>ISO-8601; year, month, day </entry>
1440
+ <entry>ISO-8601; January 8, 1999 in any mode </entry>
1434
1441
</row>
1435
1442
<row>
1436
1443
<entry>1999.008</entry>
1437
1444
<entry>year and day of year</entry>
1438
1445
</row>
1439
- <row>
1440
- <entry>99008</entry>
1441
- <entry>year and day of year</entry>
1442
- </row>
1443
1446
<row>
1444
1447
<entry>J2451187</entry>
1445
1448
<entry>Julian day</entry>
@@ -1480,7 +1483,8 @@ SELECT b, char_length(b) FROM test2;
1480
1483
<para>
1481
1484
Valid input for these types consists of a time of day followed
1482
1485
by an optional time zone. (See <xref
1483
- linkend="datatype-datetime-time-table">.) If a time zone is
1486
+ linkend="datatype-datetime-time-table">
1487
+ and <xref linkend="datatype-timezone-table">.) If a time zone is
1484
1488
specified in the input for <type>time without time zone</type>,
1485
1489
it is silently ignored.
1486
1490
</para>
@@ -1539,14 +1543,43 @@ SELECT b, char_length(b) FROM test2;
1539
1543
<entry>040506-08</entry>
1540
1544
<entry>ISO 8601</entry>
1541
1545
</row>
1546
+ <row>
1547
+ <entry>04:05:06 PST</entry>
1548
+ <entry>timezone specified by name</entry>
1549
+ </row>
1542
1550
</tbody>
1543
1551
</tgroup>
1544
1552
</table>
1545
1553
1546
- <para>
1547
- Refer to <xref linkend="datatype-timezone-table"> for
1548
- more examples of time zones.
1549
- </para>
1554
+ <table tocentry="1" id="datatype-timezone-table">
1555
+ <title>Time Zone Input</title>
1556
+ <tgroup cols="2">
1557
+ <thead>
1558
+ <row>
1559
+ <entry>Example</entry>
1560
+ <entry>Description</entry>
1561
+ </row>
1562
+ </thead>
1563
+ <tbody>
1564
+ <row>
1565
+ <entry>PST</entry>
1566
+ <entry>Pacific Standard Time</entry>
1567
+ </row>
1568
+ <row>
1569
+ <entry>-8:00</entry>
1570
+ <entry>ISO-8601 offset for PST</entry>
1571
+ </row>
1572
+ <row>
1573
+ <entry>-800</entry>
1574
+ <entry>ISO-8601 offset for PST</entry>
1575
+ </row>
1576
+ <row>
1577
+ <entry>-8</entry>
1578
+ <entry>ISO-8601 offset for PST</entry>
1579
+ </row>
1580
+ </tbody>
1581
+ </tgroup>
1582
+ </table>
1550
1583
</sect3>
1551
1584
1552
1585
<sect3>
@@ -1571,8 +1604,7 @@ SELECT b, char_length(b) FROM test2;
1571
1604
Valid input for the time stamp types consists of a concatenation
1572
1605
of a date and a time, followed by an optional
1573
1606
<literal>AD</literal> or <literal>BC</literal>, followed by an
1574
- optional time zone. (See <xref
1575
- linkend="datatype-timezone-table">.) Thus
1607
+ optional time zone. Thus
1576
1608
1577
1609
<programlisting>
1578
1610
1999-01-08 04:05:06
@@ -1626,36 +1658,6 @@ January 8 04:05:06 1999 PST
1626
1658
as <varname>timezone</> local time. A different zone reference can
1627
1659
be specified for the conversion using <literal>AT TIME ZONE</>.
1628
1660
</para>
1629
-
1630
- <table tocentry="1" id="datatype-timezone-table">
1631
- <title>Time Zone Input</title>
1632
- <tgroup cols="2">
1633
- <thead>
1634
- <row>
1635
- <entry>Example</entry>
1636
- <entry>Description</entry>
1637
- </row>
1638
- </thead>
1639
- <tbody>
1640
- <row>
1641
- <entry>PST</entry>
1642
- <entry>Pacific Standard Time</entry>
1643
- </row>
1644
- <row>
1645
- <entry>-8:00</entry>
1646
- <entry>ISO-8601 offset for PST</entry>
1647
- </row>
1648
- <row>
1649
- <entry>-800</entry>
1650
- <entry>ISO-8601 offset for PST</entry>
1651
- </row>
1652
- <row>
1653
- <entry>-8</entry>
1654
- <entry>ISO-8601 offset for PST</entry>
1655
- </row>
1656
- </tbody>
1657
- </tgroup>
1658
- </table>
1659
1661
</sect3>
1660
1662
1661
1663
<sect3>
@@ -1760,7 +1762,7 @@ January 8 04:05:06 1999 PST
1760
1762
<row>
1761
1763
<entry><literal>now</literal></entry>
1762
1764
<entry><type>date</type>, <type>time</type>, <type>timestamp</type></entry>
1763
- <entry>current transaction time</entry>
1765
+ <entry>current transaction's start time</entry>
1764
1766
</row>
1765
1767
<row>
1766
1768
<entry><literal>today</literal></entry>
@@ -1805,9 +1807,10 @@ January 8 04:05:06 1999 PST
1805
1807
</indexterm>
1806
1808
1807
1809
<para>
1808
- The output format of the date/time types can be set to one of the four styles ISO 8601,
1810
+ The output format of the date/time types can be set to one of the four
1811
+ styles ISO 8601,
1809
1812
<acronym>SQL</acronym> (Ingres), traditional POSTGRES, and
1810
- German, using the <literal>SET datestyle</literal>. The default
1813
+ German, using the command <literal>SET datestyle</literal>. The default
1811
1814
is the <acronym>ISO</acronym> format. (The
1812
1815
<acronym>SQL</acronym> standard requires the use of the ISO 8601
1813
1816
format. The name of the <quote>SQL</quote> output format is a
@@ -1854,9 +1857,10 @@ January 8 04:05:06 1999 PST
1854
1857
</table>
1855
1858
1856
1859
<para>
1857
- The <acronym>SQL</acronym> style has European and non-European
1858
- (U.S.) variants, which determines whether month follows day or
1859
- vice versa. (See <xref linkend="datatype-datetime-input">
1860
+ In the <acronym>SQL</acronym> and POSTGRES styles, day appears before
1861
+ month if DMY field ordering has been specified, otherwise month appears
1862
+ before day.
1863
+ (See <xref linkend="datatype-datetime-input">
1860
1864
for how this setting also affects interpretation of input values.)
1861
1865
<xref linkend="datatype-datetime-output2-table"> shows an
1862
1866
example.
@@ -1867,22 +1871,27 @@ January 8 04:05:06 1999 PST
1867
1871
<tgroup cols="3">
1868
1872
<thead>
1869
1873
<row>
1870
- <entry>Style Specification </entry>
1871
- <entry>Description </entry>
1872
- <entry>Example</entry>
1874
+ <entry>DateStyle setting </entry>
1875
+ <entry>Input Ordering </entry>
1876
+ <entry>Example Output </entry>
1873
1877
</row>
1874
1878
</thead>
1875
1879
<tbody>
1876
1880
<row>
1877
- <entry>European </entry>
1881
+ <entry><literal>SQL, DMY</> </entry>
1878
1882
<entry><replaceable>day</replaceable>/<replaceable>month</replaceable>/<replaceable>year</replaceable></entry>
1879
1883
<entry>17/12/1997 15:37:16.00 CET</entry>
1880
1884
</row>
1881
1885
<row>
1882
- <entry>US </entry>
1886
+ <entry><literal>SQL, MDY</> </entry>
1883
1887
<entry><replaceable>month</replaceable>/<replaceable>day</replaceable>/<replaceable>year</replaceable></entry>
1884
1888
<entry>12/17/1997 07:37:16.00 PST</entry>
1885
1889
</row>
1890
+ <row>
1891
+ <entry><literal>Postgres, DMY</></entry>
1892
+ <entry><replaceable>day</replaceable>/<replaceable>month</replaceable>/<replaceable>year</replaceable></entry>
1893
+ <entry>Wed 17 Dec 07:37:16 1997 PST</entry>
1894
+ </row>
1886
1895
</tbody>
1887
1896
</tgroup>
1888
1897
</table>
@@ -1903,7 +1912,7 @@ January 8 04:05:06 1999 PST
1903
1912
The date/time styles can be selected by the user using the
1904
1913
<command>SET datestyle</command> command, the
1905
1914
<varname>datestyle</varname> parameter in the
1906
- <filename>postgresql.conf</filename> configuration file, and the
1915
+ <filename>postgresql.conf</filename> configuration file, or the
1907
1916
<envar>PGDATESTYLE</envar> environment variable on the server or
1908
1917
client. The formatting function <function>to_char</function>
1909
1918
(see <xref linkend="functions-formatting">) is also available as
0 commit comments