Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > by-pkgid > db7d48fed1469a51f3fb965d5b5b2ac1 > files > 82

postgresql-docs-7.4.1-2.5.100mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Date/Time Types</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 7.4.1 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Data Types"
HREF="datatype.html"><LINK
REL="PREVIOUS"
TITLE="Binary Data Types"
HREF="datatype-binary.html"><LINK
REL="NEXT"
TITLE="Boolean Type"
HREF="datatype-boolean.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
NAME="creation"
CONTENT="2003-12-22T03:48:47"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 7.4.1 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype-binary.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Data Types</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="datatype.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="datatype-boolean.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="DATATYPE-DATETIME"
>8.5. Date/Time Types</A
></H1
><A
NAME="AEN3970"
></A
><A
NAME="AEN3972"
></A
><A
NAME="AEN3974"
></A
><A
NAME="AEN3976"
></A
><A
NAME="AEN3978"
></A
><A
NAME="AEN3980"
></A
><A
NAME="AEN3982"
></A
><A
NAME="AEN3984"
></A
><A
NAME="AEN3986"
></A
><P
>    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> supports the full set of
    <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> date and time types, shown in <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-TABLE"
>Table 8-9</A
>.
   </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-TABLE"
></A
><P
><B
>Table 8-9. Date/Time Types</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><COL><COL><THEAD
><TR
><TH
>Name</TH
><TH
>Storage Size</TH
><TH
>Description</TH
><TH
>Low Value</TH
><TH
>High Value</TH
><TH
>Resolution</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="TYPE"
>timestamp [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] [ without time zone ]</TT
></TD
><TD
>8 bytes</TD
><TD
>both date and time</TD
><TD
>4713 BC</TD
><TD
>5874897 AD</TD
><TD
>1 microsecond / 14 digits</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>timestamp [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] with time zone</TT
></TD
><TD
>8 bytes</TD
><TD
>both date and time, with time zone</TD
><TD
>4713 BC</TD
><TD
>5874897 AD</TD
><TD
>1 microsecond / 14 digits</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>interval [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ]</TT
></TD
><TD
>12 bytes</TD
><TD
>time intervals</TD
><TD
>-178000000 years</TD
><TD
>178000000 years</TD
><TD
>1 microsecond</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>date</TT
></TD
><TD
>4 bytes</TD
><TD
>dates only</TD
><TD
>4713 BC</TD
><TD
>32767 AD</TD
><TD
>1 day</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>time [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] [ without time zone ]</TT
></TD
><TD
>8 bytes</TD
><TD
>times of day only</TD
><TD
>00:00:00.00</TD
><TD
>23:59:59.99</TD
><TD
>1 microsecond</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>time [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] with time zone</TT
></TD
><TD
>12 bytes</TD
><TD
>times of day only, with time zone</TD
><TD
>00:00:00.00+12</TD
><TD
>23:59:59.99-12</TD
><TD
>1 microsecond</TD
></TR
></TBODY
></TABLE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>     Prior to <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 7.3, writing just
     <TT
CLASS="TYPE"
>timestamp</TT
> was equivalent to <TT
CLASS="TYPE"
>timestamp with
     time zone</TT
>.  This was changed for SQL compliance.
    </P
></BLOCKQUOTE
></DIV
><P
>    <TT
CLASS="TYPE"
>time</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
>, and
    <TT
CLASS="TYPE"
>interval</TT
> accept an optional precision value
    <VAR
CLASS="REPLACEABLE"
>p</VAR
> which specifies the number of
    fractional digits retained in the seconds field. By default, there
    is no explicit bound on precision.  The allowed range of
    <VAR
CLASS="REPLACEABLE"
>p</VAR
> is from 0 to 6 for the
    <TT
CLASS="TYPE"
>timestamp</TT
> and <TT
CLASS="TYPE"
>interval</TT
> types.
   </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>    When <TT
CLASS="TYPE"
>timestamp</TT
> values are stored as double precision floating-point
    numbers (currently the default), the effective limit of precision
    may be less than 6. <TT
CLASS="TYPE"
>timestamp</TT
> values are stored as seconds
    before or after midnight 2000-01-01.  Microsecond precision is achieved for
    dates within a few years of 2000-01-01, but the precision degrades for
    dates further away.  When <TT
CLASS="TYPE"
>timestamp</TT
> values are stored as
    eight-byte integers (a compile-time
    option), microsecond precision is available over the full range of
    values. However eight-byte integer timestamps have a more limited range of
    dates than shown above: from 4713 BC up to 294276 AD.
   </P
></BLOCKQUOTE
></DIV
><P
>    For the <TT
CLASS="TYPE"
>time</TT
> types, the allowed range of
    <VAR
CLASS="REPLACEABLE"
>p</VAR
> is from 0 to 6 when eight-byte integer
    storage is used, or from 0 to 10 when floating-point storage is used.
   </P
><P
>    The type <TT
CLASS="TYPE"
>time with time zone</TT
> is defined by the SQL
    standard, but the definition exhibits properties which lead to
    questionable usefulness. In most cases, a combination of
    <TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>time</TT
>, <TT
CLASS="TYPE"
>timestamp without time
    zone</TT
>, and <TT
CLASS="TYPE"
>timestamp with time zone</TT
> should
    provide a complete range of date/time functionality required by
    any application.
   </P
><P
>    The types <TT
CLASS="TYPE"
>abstime</TT
>
    and <TT
CLASS="TYPE"
>reltime</TT
> are lower precision types which are used internally.
    You are discouraged from using these types in new
    applications and are encouraged to move any old
    ones over when appropriate. Any or all of these internal types
    might disappear in a future release.
   </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-DATETIME-INPUT"
>8.5.1. Date/Time Input</A
></H2
><P
>     Date and time input is accepted in almost any reasonable format, including
     ISO 8601, <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>-compatible, 
     traditional <SPAN
CLASS="PRODUCTNAME"
>POSTGRES</SPAN
>, and others.
     For some formats, ordering of month, day, and year in date input is
     ambiguous and there is support for specifying the expected
     ordering of these fields.  Set the <VAR
CLASS="VARNAME"
>datestyle</VAR
> parameter
     to <TT
CLASS="LITERAL"
>MDY</TT
> to select month-day-year interpretation,
     <TT
CLASS="LITERAL"
>DMY</TT
> to select day-month-year interpretation, or
     <TT
CLASS="LITERAL"
>YMD</TT
> to select year-month-day interpretation.
    </P
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is more flexible in
     handling date/time input than the
     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard requires.
     See <A
HREF="datetime-appendix.html"
>Appendix B</A
>
     for the exact parsing rules of date/time input and for the
     recognized text fields including months, days of the week, and
     time zones. 
    </P
><P
>     Remember that any date or time literal input needs to be enclosed
     in single quotes, like text strings.  Refer to 
     <A
HREF="sql-syntax.html#SQL-SYNTAX-CONSTANTS-GENERIC"
>Section 4.1.2.4</A
> for more
     information.
     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> requires the following syntax
</P><PRE
CLASS="SYNOPSIS"
><VAR
CLASS="REPLACEABLE"
>type</VAR
> [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] '<VAR
CLASS="REPLACEABLE"
>value</VAR
>'</PRE
><P>
     where <VAR
CLASS="REPLACEABLE"
>p</VAR
> in the optional precision
     specification is an integer corresponding to the number of
     fractional digits in the seconds field. Precision can be
     specified for <TT
CLASS="TYPE"
>time</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
>, and
     <TT
CLASS="TYPE"
>interval</TT
> types.  The allowed values are mentioned
     above.  If no precision is specified in a constant specification,
     it defaults to the precision of the literal value.
    </P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4111"
>8.5.1.1. Dates</A
></H3
><A
NAME="AEN4113"
></A
><P
>     <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-DATE-TABLE"
>Table 8-10</A
> shows some possible
     inputs for the <TT
CLASS="TYPE"
>date</TT
> type.
    </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-DATE-TABLE"
></A
><P
><B
>Table 8-10. Date Input</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Example</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
>January 8, 1999</TD
><TD
>unambiguous in any <VAR
CLASS="VARNAME"
>datestyle</VAR
> input mode</TD
></TR
><TR
><TD
>1999-01-08</TD
><TD
>ISO 8601; January 8 in any mode
         (recommended format)</TD
></TR
><TR
><TD
>1/8/1999</TD
><TD
>January 8 in <TT
CLASS="LITERAL"
>MDY</TT
> mode;
          August 1 in <TT
CLASS="LITERAL"
>DMY</TT
> mode</TD
></TR
><TR
><TD
>1/18/1999</TD
><TD
>January 18 in <TT
CLASS="LITERAL"
>MDY</TT
> mode;
          rejected in other modes</TD
></TR
><TR
><TD
>01/02/03</TD
><TD
>January 2, 2003 in <TT
CLASS="LITERAL"
>MDY</TT
> mode;
          February 1, 2003 in <TT
CLASS="LITERAL"
>DMY</TT
> mode;
          February 3, 2001 in <TT
CLASS="LITERAL"
>YMD</TT
> mode
         </TD
></TR
><TR
><TD
>1999-Jan-08</TD
><TD
>January 8 in any mode</TD
></TR
><TR
><TD
>Jan-08-1999</TD
><TD
>January 8 in any mode</TD
></TR
><TR
><TD
>08-Jan-1999</TD
><TD
>January 8 in any mode</TD
></TR
><TR
><TD
>99-Jan-08</TD
><TD
>January 8 in <TT
CLASS="LITERAL"
>YMD</TT
> mode, else error</TD
></TR
><TR
><TD
>08-Jan-99</TD
><TD
>January 8, except error in <TT
CLASS="LITERAL"
>YMD</TT
> mode</TD
></TR
><TR
><TD
>Jan-08-99</TD
><TD
>January 8, except error in <TT
CLASS="LITERAL"
>YMD</TT
> mode</TD
></TR
><TR
><TD
>19990108</TD
><TD
>ISO 8601; January 8, 1999 in any mode</TD
></TR
><TR
><TD
>990108</TD
><TD
>ISO 8601; January 8, 1999 in any mode</TD
></TR
><TR
><TD
>1999.008</TD
><TD
>year and day of year</TD
></TR
><TR
><TD
>J2451187</TD
><TD
>Julian day</TD
></TR
><TR
><TD
>January 8, 99 BC</TD
><TD
>year 99 before the Common Era</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4184"
>8.5.1.2. Times</A
></H3
><A
NAME="AEN4186"
></A
><A
NAME="AEN4188"
></A
><A
NAME="AEN4190"
></A
><P
>      The time-of-day types are <TT
CLASS="TYPE"
>time [
      (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] without time zone</TT
> and
      <TT
CLASS="TYPE"
>time [ (<VAR
CLASS="REPLACEABLE"
>p</VAR
>) ] with time
      zone</TT
>.  Writing just <TT
CLASS="TYPE"
>time</TT
> is equivalent to
      <TT
CLASS="TYPE"
>time without time zone</TT
>.
     </P
><P
>      Valid input for these types consists of a time of day followed
      by an optional time zone. (See <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-TIME-TABLE"
>Table 8-11</A
> 
      and <A
HREF="datatype-datetime.html#DATATYPE-TIMEZONE-TABLE"
>Table 8-12</A
>.)  If a time zone is
      specified in the input for <TT
CLASS="TYPE"
>time without time zone</TT
>,
      it is silently ignored.
     </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-TIME-TABLE"
></A
><P
><B
>Table 8-11. Time Input</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Example</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>04:05:06.789</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05:06</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>040506</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05 AM</TT
></TD
><TD
>same as 04:05; AM does not affect value</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05 PM</TT
></TD
><TD
>same as 16:05; input hour must be &#60;= 12</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05:06.789-8</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05:06-08:00</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05-08:00</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>040506-08</TT
></TD
><TD
>ISO 8601</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>04:05:06 PST</TT
></TD
><TD
>time zone specified by name</TD
></TR
></TBODY
></TABLE
></DIV
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-TIMEZONE-TABLE"
></A
><P
><B
>Table 8-12. Time Zone Input</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Example</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>PST</TT
></TD
><TD
>Pacific Standard Time</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-8:00</TT
></TD
><TD
>ISO-8601 offset for PST</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-800</TT
></TD
><TD
>ISO-8601 offset for PST</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-8</TT
></TD
><TD
>ISO-8601 offset for PST</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>zulu</TT
></TD
><TD
>Military abbreviation for UTC</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>z</TT
></TD
><TD
>Short form of <TT
CLASS="LITERAL"
>zulu</TT
></TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4288"
>8.5.1.3. Time Stamps</A
></H3
><A
NAME="AEN4290"
></A
><A
NAME="AEN4292"
></A
><A
NAME="AEN4294"
></A
><P
>      Valid input for the time stamp types consists of a concatenation
      of a date and a time, followed by an optional
      <TT
CLASS="LITERAL"
>AD</TT
> or <TT
CLASS="LITERAL"
>BC</TT
>, followed by an
      optional time zone. Thus

</P><PRE
CLASS="PROGRAMLISTING"
>1999-01-08 04:05:06</PRE
><P>
      and
</P><PRE
CLASS="PROGRAMLISTING"
>1999-01-08 04:05:06 -8:00</PRE
><P>

      are valid values, which follow the <ACRONYM
CLASS="ACRONYM"
>ISO</ACRONYM
> 8601
      standard.  In addition, the wide-spread format

</P><PRE
CLASS="PROGRAMLISTING"
>January 8 04:05:06 1999 PST</PRE
><P>
      is supported.
     </P
><P
>      For <TT
CLASS="TYPE"
>timestamp [without time zone]</TT
>, any explicit time
      zone specified in the input is silently ignored. That is, the
      resulting date/time value is derived from the explicit date/time
      fields in the input value, and is not adjusted for time zone.
     </P
><P
>      For <TT
CLASS="TYPE"
>timestamp with time zone</TT
>, the internally stored
      value is always in UTC (Universal
      Coordinated Time, traditionally known as Greenwich Mean Time,
      <ACRONYM
CLASS="ACRONYM"
>GMT</ACRONYM
>).  An input value that has an explicit
      time zone specified is converted to UTC using the appropriate offset
      for that time zone.  If no time zone is stated in the input string,
      then it is assumed to be in the time zone indicated by the system's
      <VAR
CLASS="VARNAME"
>timezone</VAR
> parameter, and is converted to UTC using the
      offset for the <VAR
CLASS="VARNAME"
>timezone</VAR
> zone.
     </P
><P
>      When a <TT
CLASS="TYPE"
>timestamp with time
      zone</TT
> value is output, it is always converted from UTC to the
      current <VAR
CLASS="VARNAME"
>timezone</VAR
> zone, and displayed as local time in that
      zone.  To see the time in another time zone, either change
      <VAR
CLASS="VARNAME"
>timezone</VAR
> or use the <TT
CLASS="LITERAL"
>AT TIME ZONE</TT
> construct
      (see <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT"
>Section 9.8.3</A
>).
     </P
><P
>      Conversions between <TT
CLASS="TYPE"
>timestamp without time zone</TT
> and
      <TT
CLASS="TYPE"
>timestamp with time zone</TT
> normally assume that the
      <TT
CLASS="TYPE"
>timestamp without time zone</TT
> value should be taken or given
      as <VAR
CLASS="VARNAME"
>timezone</VAR
> local time.  A different zone reference can
      be specified for the conversion using <TT
CLASS="LITERAL"
>AT TIME ZONE</TT
>.
     </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4322"
>8.5.1.4. Intervals</A
></H3
><A
NAME="AEN4324"
></A
><P
>       <TT
CLASS="TYPE"
>interval</TT
> values can be written with the following syntax:

</P><PRE
CLASS="PROGRAMLISTING"
>[<SPAN
CLASS="OPTIONAL"
>@</SPAN
>] <VAR
CLASS="REPLACEABLE"
>quantity</VAR
> <VAR
CLASS="REPLACEABLE"
>unit</VAR
> [<SPAN
CLASS="OPTIONAL"
><VAR
CLASS="REPLACEABLE"
>quantity</VAR
> <VAR
CLASS="REPLACEABLE"
>unit</VAR
>...</SPAN
>] [<SPAN
CLASS="OPTIONAL"
><VAR
CLASS="REPLACEABLE"
>direction</VAR
></SPAN
>]</PRE
><P>

      Where: <VAR
CLASS="REPLACEABLE"
>quantity</VAR
> is a number (possibly signed);
      <VAR
CLASS="REPLACEABLE"
>unit</VAR
> is <TT
CLASS="LITERAL"
>second</TT
>,
      <TT
CLASS="LITERAL"
>minute</TT
>, <TT
CLASS="LITERAL"
>hour</TT
>, <TT
CLASS="LITERAL"
>day</TT
>,
      <TT
CLASS="LITERAL"
>week</TT
>, <TT
CLASS="LITERAL"
>month</TT
>, <TT
CLASS="LITERAL"
>year</TT
>,
      <TT
CLASS="LITERAL"
>decade</TT
>, <TT
CLASS="LITERAL"
>century</TT
>, <TT
CLASS="LITERAL"
>millennium</TT
>,
      or abbreviations or plurals of these units;
      <VAR
CLASS="REPLACEABLE"
>direction</VAR
> can be <TT
CLASS="LITERAL"
>ago</TT
> or
      empty.  The at sign (<TT
CLASS="LITERAL"
>@</TT
>) is optional noise.  The amounts
      of different units are implicitly added up with appropriate
      sign accounting.
     </P
><P
>      Quantities of days, hours, minutes, and seconds can be specified without
      explicit unit markings.  For example, <TT
CLASS="LITERAL"
>'1 12:59:10'</TT
> is read
      the same as <TT
CLASS="LITERAL"
>'1 day 12 hours 59 min 10 sec'</TT
>.
     </P
><P
>      The optional precision
      <VAR
CLASS="REPLACEABLE"
>p</VAR
> should be between 0 and 6, and
      defaults to the precision of the input literal.
     </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4357"
>8.5.1.5. Special Values</A
></H3
><A
NAME="AEN4359"
></A
><A
NAME="AEN4362"
></A
><P
>      The following <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>-compatible functions can be
      used as date or time values for the corresponding data type: 
      <TT
CLASS="LITERAL"
>CURRENT_DATE</TT
>, <TT
CLASS="LITERAL"
>CURRENT_TIME</TT
>, 
      <TT
CLASS="LITERAL"
>CURRENT_TIMESTAMP</TT
>, <TT
CLASS="LITERAL"
>LOCALTIME</TT
>, 
      <TT
CLASS="LITERAL"
>LOCALTIMESTAMP</TT
>.  The latter four accept an 
      optional precision specification.  (See also <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-CURRENT"
>Section 9.8.4</A
>.)
     </P
><P
>      <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> also supports several
      special date/time input values for convenience, as shown in <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-TABLE"
>Table 8-13</A
>.  The values
      <TT
CLASS="LITERAL"
>infinity</TT
> and <TT
CLASS="LITERAL"
>-infinity</TT
>
      are specially represented inside the system and will be displayed
      the same way; but the others are simply notational shorthands
      that will be converted to ordinary date/time values when read.
      All of these values are treated as normal constants and need to be
      written in single quotes.
     </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-SPECIAL-TABLE"
></A
><P
><B
>Table 8-13. Special Date/Time Inputs</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Input String</TH
><TH
>Valid Types</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>epoch</TT
></TD
><TD
><TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>1970-01-01 00:00:00+00 (Unix system time zero)</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>infinity</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>later than all other time stamps</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>-infinity</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>earlier than all other time stamps</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>now</TT
></TD
><TD
><TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>time</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>current transaction's start time</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>today</TT
></TD
><TD
><TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>midnight today</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>tomorrow</TT
></TD
><TD
><TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>midnight tomorrow</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>yesterday</TT
></TD
><TD
><TT
CLASS="TYPE"
>date</TT
>, <TT
CLASS="TYPE"
>timestamp</TT
></TD
><TD
>midnight yesterday</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>allballs</TT
></TD
><TD
><TT
CLASS="TYPE"
>time</TT
></TD
><TD
>00:00:00.00 UTC</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-DATETIME-OUTPUT"
>8.5.2. Date/Time Output</A
></H2
><A
NAME="AEN4443"
></A
><A
NAME="AEN4447"
></A
><P
>     The output format of the date/time types can be set to one of the four
     styles ISO 8601,
     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> (Ingres), traditional POSTGRES, and
     German, using the command <TT
CLASS="LITERAL"
>SET datestyle</TT
>.  The default
     is the <ACRONYM
CLASS="ACRONYM"
>ISO</ACRONYM
> format.  (The
     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard requires the use of the ISO 8601
     format.  The name of the <SPAN
CLASS="QUOTE"
>"SQL"</SPAN
> output format is a
     historical accident.)  <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-OUTPUT-TABLE"
>Table 8-14</A
> shows examples of each
     output style.  The output of the <TT
CLASS="TYPE"
>date</TT
> and
     <TT
CLASS="TYPE"
>time</TT
> types is of course only the date or time part
     in accordance with the given examples.
    </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-OUTPUT-TABLE"
></A
><P
><B
>Table 8-14. Date/Time Output Styles</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Style Specification</TH
><TH
>Description</TH
><TH
>Example</TH
></TR
></THEAD
><TBODY
><TR
><TD
>ISO</TD
><TD
>ISO 8601/SQL standard</TD
><TD
>1997-12-17 07:37:16-08</TD
></TR
><TR
><TD
>SQL</TD
><TD
>traditional style</TD
><TD
>12/17/1997 07:37:16.00 PST</TD
></TR
><TR
><TD
>POSTGRES</TD
><TD
>original style</TD
><TD
>Wed Dec 17 07:37:16 1997 PST</TD
></TR
><TR
><TD
>German</TD
><TD
>regional style</TD
><TD
>17.12.1997 07:37:16.00 PST</TD
></TR
></TBODY
></TABLE
></DIV
><P
>     In the <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> and POSTGRES styles, day appears before
     month if DMY field ordering has been specified, otherwise month appears
     before day.
     (See <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-INPUT"
>Section 8.5.1</A
>
     for how this setting also affects interpretation of input values.)
     <A
HREF="datatype-datetime.html#DATATYPE-DATETIME-OUTPUT2-TABLE"
>Table 8-15</A
> shows an
     example.
    </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-DATETIME-OUTPUT2-TABLE"
></A
><P
><B
>Table 8-15. Date Order Conventions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
><VAR
CLASS="VARNAME"
>datestyle</VAR
> Setting</TH
><TH
>Input Ordering</TH
><TH
>Example Output</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>SQL, DMY</TT
></TD
><TD
><VAR
CLASS="REPLACEABLE"
>day</VAR
>/<VAR
CLASS="REPLACEABLE"
>month</VAR
>/<VAR
CLASS="REPLACEABLE"
>year</VAR
></TD
><TD
>17/12/1997 15:37:16.00 CET</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>SQL, MDY</TT
></TD
><TD
><VAR
CLASS="REPLACEABLE"
>month</VAR
>/<VAR
CLASS="REPLACEABLE"
>day</VAR
>/<VAR
CLASS="REPLACEABLE"
>year</VAR
></TD
><TD
>12/17/1997 07:37:16.00 PST</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>Postgres, DMY</TT
></TD
><TD
><VAR
CLASS="REPLACEABLE"
>day</VAR
>/<VAR
CLASS="REPLACEABLE"
>month</VAR
>/<VAR
CLASS="REPLACEABLE"
>year</VAR
></TD
><TD
>Wed 17 Dec 07:37:16 1997 PST</TD
></TR
></TBODY
></TABLE
></DIV
><P
>     <TT
CLASS="TYPE"
>interval</TT
> output looks like the input format, except
     that units like <TT
CLASS="LITERAL"
>century</TT
> or
     <TT
CLASS="LITERAL"
>wek</TT
> are converted to years and days and that
     <TT
CLASS="LITERAL"
>ago</TT
> is converted to an appropriate sign.  In
     ISO mode the output looks like

</P><PRE
CLASS="PROGRAMLISTING"
>[<SPAN
CLASS="OPTIONAL"
> <VAR
CLASS="REPLACEABLE"
>quantity</VAR
> <VAR
CLASS="REPLACEABLE"
>unit</VAR
> [<SPAN
CLASS="OPTIONAL"
> ... </SPAN
>] </SPAN
>] [<SPAN
CLASS="OPTIONAL"
> <VAR
CLASS="REPLACEABLE"
>days</VAR
> </SPAN
>] [<SPAN
CLASS="OPTIONAL"
> <VAR
CLASS="REPLACEABLE"
>hours</VAR
>:<VAR
CLASS="REPLACEABLE"
>minutes</VAR
>:<VAR
CLASS="REPLACEABLE"
>sekunden</VAR
> </SPAN
>]</PRE
><P>
    </P
><P
>     The date/time styles can be selected by the user using the
     <TT
CLASS="COMMAND"
>SET datestyle</TT
> command, the
     <VAR
CLASS="VARNAME"
>datestyle</VAR
> parameter in the
     <TT
CLASS="FILENAME"
>postgresql.conf</TT
> configuration file, or the
     <TT
CLASS="ENVAR"
>PGDATESTYLE</TT
> environment variable on the server or
     client.  The formatting function <CODE
CLASS="FUNCTION"
>to_char</CODE
>
     (see <A
HREF="functions-formatting.html"
>Section 9.7</A
>) is also available as
     a more flexible way to format the date/time output.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-TIMEZONES"
>8.5.3. Time Zones</A
></H2
><A
NAME="AEN4548"
></A
><P
>    Time zones, and time-zone conventions, are influenced by
    political decisions, not just earth geometry. Time zones around the
    world became somewhat standardized during the 1900's,
    but continue to be prone to arbitrary changes.
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> uses your operating
    system's underlying features to provide output time-zone
    support, and these systems usually contain information for only
    the time period 1902 through 2038 (corresponding to the full
    range of conventional Unix system time).
    <TT
CLASS="TYPE"
>timestamp with time zone</TT
> and <TT
CLASS="TYPE"
>time with time
     zone</TT
> will use time zone
    information only within that year range, and assume that times
    outside that range are in <ACRONYM
CLASS="ACRONYM"
>UTC</ACRONYM
>.
    But since time zone support is derived from the underlying operating
    system time-zone capabilities, it can handle daylight-saving time
    and other special behavior.
   </P
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> endeavors to be compatible with
     the <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard definitions for typical usage.
     However, the <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard has an odd mix of date and
     time types and capabilities. Two obvious problems are:

     <P
></P
></P><UL
><LI
><P
>        Although the <TT
CLASS="TYPE"
>date</TT
> type 
        does not have an associated time zone, the
        <TT
CLASS="TYPE"
>time</TT
> type can.
        Time zones in the real world can have no meaning unless 
        associated with a date as well as a time
        since the offset may vary through the year with daylight-saving
        time boundaries.
       </P
></LI
><LI
><P
>        The default time zone is specified as a constant numeric offset 
        from <ACRONYM
CLASS="ACRONYM"
>UTC</ACRONYM
>. It is not possible to adapt to daylight-saving
        time when doing date/time arithmetic across
        <ACRONYM
CLASS="ACRONYM"
>DST</ACRONYM
> boundaries.
       </P
></LI
></UL
><P>
    </P
><P
>     To address these difficulties, we recommend using date/time types
     that contain both date and time when using time zones. We
     recommend <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>not</I
></SPAN
> using the type <TT
CLASS="TYPE"
>time with
     time zone</TT
> (though it is supported by
     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> for legacy applications and
     for compatibility with other <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>
     implementations).  <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> assumes
     your local time zone for any type containing only date or time.
    </P
><P
>     All dates and times are stored internally in
     <ACRONYM
CLASS="ACRONYM"
>UTC</ACRONYM
>.  Times are converted to local time
     on the database server before being sent to the client,
     hence by default are in the server time zone.
    </P
><P
>     There are several ways to select the time zone used by the server:

     <P
></P
></P><UL
><LI
><P
>        The <TT
CLASS="ENVAR"
>TZ</TT
> environment variable on the server host
        is used by the server as the default time zone, if no other is
        specified.
       </P
></LI
><LI
><P
>        The <VAR
CLASS="VARNAME"
>timezone</VAR
> configuration parameter can be
        set in the file <TT
CLASS="FILENAME"
>postgresql.conf</TT
>.
       </P
></LI
><LI
><P
>        The <TT
CLASS="ENVAR"
>PGTZ</TT
> environment variable, if set at the
        client, is used by <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
        applications to send a <TT
CLASS="COMMAND"
>SET TIME ZONE</TT
>
        command to the server upon connection.
       </P
></LI
><LI
><P
>        The <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> command <TT
CLASS="COMMAND"
>SET TIME ZONE</TT
>
        sets the time zone for the session.
       </P
></LI
></UL
><P>
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>       If an invalid time zone is specified, the time zone becomes
       <ACRONYM
CLASS="ACRONYM"
>UTC</ACRONYM
> (on most systems anyway).
      </P
></BLOCKQUOTE
></DIV
><P
>    Refer to <A
HREF="datetime-appendix.html"
>Appendix B</A
> for a list of
    available time zones.
   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-DATETIME-INTERNALS"
>8.5.4. Internals</A
></H2
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> uses Julian dates
     for all date/time calculations. They have the nice property of correctly
     predicting/calculating any date more recent than 4713 BC
     to far into the future, using the assumption that the length of the
     year is 365.2425 days.
    </P
><P
>     Date conventions before the 19th century make for interesting reading,
     but are not consistent enough to warrant coding into a date/time handler.
    </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype-binary.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="datatype-boolean.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Binary Data Types</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Boolean Type</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>