Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > bab02a23fa9f3df8d66a9a3231b50245 > files > 127

postgresql8.3-docs-8.3.6-2mdv2008.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Date/Time Types</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.3.6 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
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2009-02-03T04:34:16"></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 8.3.6 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="AEN4588"
></A
><A
NAME="AEN4590"
></A
><A
NAME="AEN4592"
></A
><A
NAME="AEN4594"
></A
><A
NAME="AEN4596"
></A
><A
NAME="AEN4598"
></A
><A
NAME="AEN4600"
></A
><A
NAME="AEN4602"
></A
><A
NAME="AEN4604"
></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
>.  The operations available
    on these data types are described in
    <A
HREF="functions-datetime.html"
>Section 9.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 [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] [ 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 [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] 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 [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ]</TT
></TD
><TD
>12 bytes</TD
><TD
>time intervals</TD
><TD
>-178000000 years</TD
><TD
>178000000 years</TD
><TD
>1 microsecond / 14 digits</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>date</TT
></TD
><TD
>4 bytes</TD
><TD
>dates only</TD
><TD
>4713 BC</TD
><TD
>5874897 AD</TD
><TD
>1 day</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>time [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] [ without time zone ]</TT
></TD
><TD
>8 bytes</TD
><TD
>times of day only</TD
><TD
>00:00:00</TD
><TD
>24:00:00</TD
><TD
>1 microsecond / 14 digits</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>time [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] with time zone</TT
></TD
><TD
>12 bytes</TD
><TD
>times of day only, with time zone</TD
><TD
>00:00:00+1459</TD
><TD
>24:00:00-1459</TD
><TD
>1 microsecond / 14 digits</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
    <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> 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
    <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> 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
    might 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.  The same
    compile-time option also determines whether <TT
CLASS="TYPE"
>time</TT
> and
    <TT
CLASS="TYPE"
>interval</TT
> values are stored as floating-point or eight-byte
    integers.  In the floating-point case, large <TT
CLASS="TYPE"
>interval</TT
> values
    degrade in precision as the size of the interval increases.
   </P
></BLOCKQUOTE
></DIV
><P
>    For the <TT
CLASS="TYPE"
>time</TT
> types, the allowed range of
    <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> 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 <A
HREF="runtime-config-client.html#GUC-DATESTYLE"
>DateStyle</A
> 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-lexical.html#SQL-SYNTAX-CONSTANTS-GENERIC"
>Section 4.1.2.5</A
> for more
     information.
     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> requires the following syntax
</P><PRE
CLASS="SYNOPSIS"
><TT
CLASS="REPLACEABLE"
><I
>type</I
></TT
> [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] '<TT
CLASS="REPLACEABLE"
><I
>value</I
></TT
>'</PRE
><P>
     where <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> 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="AEN4733"
>8.5.1.1. Dates</A
></H3
><A
NAME="AEN4735"
></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 <TT
CLASS="VARNAME"
>datestyle</TT
> 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="AEN4806"
>8.5.1.2. Times</A
></H3
><A
NAME="AEN4808"
></A
><A
NAME="AEN4810"
></A
><A
NAME="AEN4812"
></A
><P
>      The time-of-day types are <TT
CLASS="TYPE"
>time [
      (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] without time zone</TT
> and
      <TT
CLASS="TYPE"
>time [ (<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>) ] 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. You can also specify a date but it will
      be ignored, except when you use a time zone name that involves a
      daylight-savings rule, such as
      <TT
CLASS="LITERAL"
>America/New_York</TT
>. In this case specifying the date
      is required in order to determine whether standard or daylight-savings
      time applies.  The appropriate time zone offset is recorded in the
      <TT
CLASS="TYPE"
>time with time zone</TT
> value.
     </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 &lt;= 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 abbreviation</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>2003-04-12 04:05:06 America/New_York</TT
></TD
><TD
>time zone specified by full 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
>Abbreviation (for Pacific Standard Time)</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>America/New_York</TT
></TD
><TD
>Full time zone name</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>PST8PDT</TT
></TD
><TD
>POSIX-style time zone specification</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
><P
>     Refer to <A
HREF="datatype-datetime.html#DATATYPE-TIMEZONES"
>Section 8.5.3</A
> for more information on how
     to specify time zones.
    </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN4926"
>8.5.1.3. Time Stamps</A
></H3
><A
NAME="AEN4928"
></A
><A
NAME="AEN4930"
></A
><A
NAME="AEN4932"
></A
><P
>      Valid input for the time stamp types consists of a concatenation
      of a date and a time, followed by an optional time zone,
      followed by an optional <TT
CLASS="LITERAL"
>AD</TT
> or <TT
CLASS="LITERAL"
>BC</TT
>.
      (Alternatively, <TT
CLASS="LITERAL"
>AD</TT
>/<TT
CLASS="LITERAL"
>BC</TT
> can appear
      before the time zone, but this is not the preferred ordering.)
      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
>      The <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard differentiates <TT
CLASS="TYPE"
>timestamp without time zone</TT
> 
      and <TT
CLASS="TYPE"
>timestamp with time zone</TT
> literals by the presence of a 
      <SPAN
CLASS="QUOTE"
>"+"</SPAN
> or <SPAN
CLASS="QUOTE"
>"-"</SPAN
>. Hence, according to the standard, 
      </P><PRE
CLASS="PROGRAMLISTING"
>TIMESTAMP '2004-10-19 10:23:54'</PRE
><P>
      is a <TT
CLASS="TYPE"
>timestamp without time zone</TT
>, while
      </P><PRE
CLASS="PROGRAMLISTING"
>TIMESTAMP '2004-10-19 10:23:54+02'</PRE
><P>
      is a <TT
CLASS="TYPE"
>timestamp with time zone</TT
>.
      <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> never examines the content of a
      literal string before determining its type, and therefore will treat
      both of the above as <TT
CLASS="TYPE"
>timestamp without time zone</TT
>.  To
      ensure that a literal is treated as <TT
CLASS="TYPE"
>timestamp with time
      zone</TT
>, give it the correct explicit type:
      </P><PRE
CLASS="PROGRAMLISTING"
>TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02'</PRE
><P>
      In a literal that has been decided to be <TT
CLASS="TYPE"
>timestamp without time
      zone</TT
>, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> will silently ignore
      any time zone indication.
      That is, the resulting value is derived from the 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
      <A
HREF="runtime-config-client.html#GUC-TIMEZONE"
>timezone</A
> parameter, and is converted to UTC using the
      offset for the <TT
CLASS="VARNAME"
>timezone</TT
> 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 <TT
CLASS="VARNAME"
>timezone</TT
> zone, and displayed as local time in that
      zone.  To see the time in another time zone, either change
      <TT
CLASS="VARNAME"
>timezone</TT
> or use the <TT
CLASS="LITERAL"
>AT TIME ZONE</TT
> construct
      (see <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT"
>Section 9.9.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 <TT
CLASS="VARNAME"
>timezone</TT
> 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="AEN4976"
>8.5.1.4. Intervals</A
></H3
><A
NAME="AEN4978"
></A
><P
>       <TT
CLASS="TYPE"
>interval</TT
> values can be written with the following syntax:

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

      Where: <TT
CLASS="REPLACEABLE"
><I
>quantity</I
></TT
> is a number (possibly signed);
      <TT
CLASS="REPLACEABLE"
><I
>unit</I
></TT
> is <TT
CLASS="LITERAL"
>microsecond</TT
>,
      <TT
CLASS="LITERAL"
>millisecond</TT
>, <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;
      <TT
CLASS="REPLACEABLE"
><I
>direction</I
></TT
> 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 subsecond precision <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> should 
      be between 0 and 6, and defaults to the precision of the input literal.
     </P
><P
>      Internally <TT
CLASS="TYPE"
>interval</TT
> values are stored as months, days,
      and seconds. This is done because the number of days in a month
      varies, and a day can have 23 or 25 hours if a daylight savings
      time adjustment is involved. Because intervals are usually created
      from constant strings or <TT
CLASS="TYPE"
>timestamp</TT
> subtraction, this
      storage method works well in most cases. Functions
      <CODE
CLASS="FUNCTION"
>justify_days</CODE
> and <CODE
CLASS="FUNCTION"
>justify_hours</CODE
> are
      available for adjusting days and hours that overflow their normal
      periods.
     </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN5018"
>8.5.1.5. Special Values</A
></H3
><A
NAME="AEN5020"
></A
><A
NAME="AEN5023"
></A
><P
>      <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 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.
      (In particular, <TT
CLASS="LITERAL"
>now</TT
> and related strings are converted
      to a specific time value as soon as they are read.)
      All of these values need to be written in single quotes when used
      as constants in SQL commands.
     </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><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
><P
>      The following <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>-compatible functions can also
      be used to obtain the current time value 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 subsecond precision specification.  (See <A
HREF="functions-datetime.html#FUNCTIONS-DATETIME-CURRENT"
>Section 9.9.4</A
>.)  Note however that these are
      SQL functions and are <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>not</I
></SPAN
> recognized as data input strings.
     </P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-DATETIME-OUTPUT"
>8.5.2. Date/Time Output</A
></H2
><A
NAME="AEN5106"
></A
><A
NAME="AEN5110"
></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
><TT
CLASS="VARNAME"
>datestyle</TT
> Setting</TH
><TH
>Input Ordering</TH
><TH
>Example Output</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
>SQL, DMY</TT
></TD
><TD
><TT
CLASS="REPLACEABLE"
><I
>day</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>month</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>year</I
></TT
></TD
><TD
>17/12/1997 15:37:16.00 CET</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>SQL, MDY</TT
></TD
><TD
><TT
CLASS="REPLACEABLE"
><I
>month</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>day</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>year</I
></TT
></TD
><TD
>12/17/1997 07:37:16.00 PST</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
>Postgres, DMY</TT
></TD
><TD
><TT
CLASS="REPLACEABLE"
><I
>day</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>month</I
></TT
>/<TT
CLASS="REPLACEABLE"
><I
>year</I
></TT
></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"
>week</TT
> are converted to years and days and
     <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"
> <TT
CLASS="REPLACEABLE"
><I
>quantity</I
></TT
> <TT
CLASS="REPLACEABLE"
><I
>unit</I
></TT
> [<SPAN
CLASS="OPTIONAL"
> ... </SPAN
>] </SPAN
>] [<SPAN
CLASS="OPTIONAL"
> <TT
CLASS="REPLACEABLE"
><I
>days</I
></TT
> </SPAN
>] [<SPAN
CLASS="OPTIONAL"
> <TT
CLASS="REPLACEABLE"
><I
>hours</I
></TT
>:<TT
CLASS="REPLACEABLE"
><I
>minutes</I
></TT
>:<TT
CLASS="REPLACEABLE"
><I
>seconds</I
></TT
> </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 <A
HREF="runtime-config-client.html#GUC-DATESTYLE"
>DateStyle</A
> 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.8</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="AEN5211"
></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, particularly with
    respect to daylight-savings rules.
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> currently supports daylight-savings
    rules over the time period 1902 through 2038 (corresponding to the full
    range of conventional Unix system time).  Times outside that range are
    taken to be in <SPAN
CLASS="QUOTE"
>"standard time"</SPAN
> for the selected time zone, no
    matter what part of the year they fall in.
   </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 have little meaning unless 
        associated with a date as well as a time,
        since the offset can 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 therefore 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 compliance with the <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard).
     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> assumes
     your local time zone for any type containing only date or time.
    </P
><P
>     All timezone-aware dates and times are stored internally in
     <ACRONYM
CLASS="ACRONYM"
>UTC</ACRONYM
>.  They are converted to local time
     in the zone specified by the <A
HREF="runtime-config-client.html#GUC-TIMEZONE"
>timezone</A
> configuration
     parameter before being displayed to the client.
    </P
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> allows you to specify time zones in
     three different forms:
     <P
></P
></P><UL
><LI
><P
>        A full time zone name, for example <TT
CLASS="LITERAL"
>America/New_York</TT
>.
        The recognized time zone names are listed in the
        <TT
CLASS="LITERAL"
>pg_timezone_names</TT
> view (see <A
HREF="view-pg-timezone-names.html"
>Section 44.56</A
>).
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> uses the widely-used
        <TT
CLASS="LITERAL"
>zic</TT
> time zone data for this purpose, so the same
        names are also recognized by much other software.
       </P
></LI
><LI
><P
>        A time zone abbreviation, for example <TT
CLASS="LITERAL"
>PST</TT
>.  Such a
        specification merely defines a particular offset from UTC, in
        contrast to full time zone names which might imply a set of daylight
        savings transition-date rules as well.  The recognized abbreviations
        are listed in the <TT
CLASS="LITERAL"
>pg_timezone_abbrevs</TT
> view (see <A
HREF="view-pg-timezone-abbrevs.html"
>Section 44.55</A
>).  You cannot set the
        configuration parameters <A
HREF="runtime-config-client.html#GUC-TIMEZONE"
>timezone</A
> or
        <A
HREF="runtime-config-logging.html#GUC-LOG-TIMEZONE"
>log_timezone</A
> using a time
        zone abbreviation, but you can use abbreviations in
        date/time input values and with the <TT
CLASS="LITERAL"
>AT TIME ZONE</TT
>
        operator.
       </P
></LI
><LI
><P
>        In addition to the timezone names and abbreviations,
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> will accept POSIX-style time zone
        specifications of the form <TT
CLASS="REPLACEABLE"
><I
>STD</I
></TT
><TT
CLASS="REPLACEABLE"
><I
>offset</I
></TT
> or
        <TT
CLASS="REPLACEABLE"
><I
>STD</I
></TT
><TT
CLASS="REPLACEABLE"
><I
>offset</I
></TT
><TT
CLASS="REPLACEABLE"
><I
>DST</I
></TT
>, where
        <TT
CLASS="REPLACEABLE"
><I
>STD</I
></TT
> is a zone abbreviation, <TT
CLASS="REPLACEABLE"
><I
>offset</I
></TT
> is a
        numeric offset in hours west from UTC, and <TT
CLASS="REPLACEABLE"
><I
>DST</I
></TT
> is an
        optional daylight-savings zone abbreviation, assumed to stand for one
        hour ahead of the given offset. For example, if <TT
CLASS="LITERAL"
>EST5EDT</TT
>
        were not already a recognized zone name, it would be accepted and would
        be functionally equivalent to USA East Coast time.  When a
        daylight-savings zone name is present, it is assumed to be used
        according to the same daylight-savings transition rules used in the
        <TT
CLASS="LITERAL"
>zic</TT
> time zone database's <TT
CLASS="FILENAME"
>posixrules</TT
> entry.
        In a standard <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> installation,
        <TT
CLASS="FILENAME"
>posixrules</TT
> is the same as <TT
CLASS="LITERAL"
>US/Eastern</TT
>, so
        that POSIX-style time zone specifications follow USA daylight-savings
        rules.  If needed, you can adjust this behavior by replacing the
        <TT
CLASS="FILENAME"
>posixrules</TT
> file.
       </P
></LI
></UL
><P>

     There is a conceptual and practical difference between the abbreviations
     and the full names: abbreviations always represent a fixed offset from
     UTC, whereas most of the full names imply a local daylight-savings time
     rule and so have two possible UTC offsets.
    </P
><P
>     One should be wary that the POSIX-style time zone feature can
     lead to silently accepting bogus input, since there is no check on the
     reasonableness of the zone abbreviations.  For example, <TT
CLASS="LITERAL"
>SET
     TIMEZONE TO FOOBAR0</TT
> will work, leaving the system effectively using
     a rather peculiar abbreviation for UTC.
     Another issue to keep in mind is that in POSIX time zone names,
     positive offsets are used for locations <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>west</I
></SPAN
> of Greenwich.
     Everywhere else, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> follows the
     ISO-8601 convention that positive timezone offsets are <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>east</I
></SPAN
>
     of Greenwich.
    </P
><P
>     In all cases, timezone names are recognized case-insensitively.
     (This is a change from <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> versions
     prior to 8.2, which were case-sensitive in some contexts and not others.)
    </P
><P
>     Neither full names nor abbreviations are hard-wired into the server;
     they are obtained from configuration files stored under
     <TT
CLASS="FILENAME"
>.../share/timezone/</TT
> and <TT
CLASS="FILENAME"
>.../share/timezonesets/</TT
>
     of the installation directory
     (see <A
HREF="datetime-config-files.html"
>Section B.3</A
>).
    </P
><P
>     The <A
HREF="runtime-config-client.html#GUC-TIMEZONE"
>timezone</A
> configuration parameter can
     be set in the file <TT
CLASS="FILENAME"
>postgresql.conf</TT
>, or in any of the
     other standard ways described in <A
HREF="runtime-config.html"
>Chapter 18</A
>.
     There are also several special ways to set it:

     <P
></P
></P><UL
><LI
><P
>        If <TT
CLASS="VARNAME"
>timezone</TT
> is not specified in
        <TT
CLASS="FILENAME"
>postgresql.conf</TT
> nor as a server command-line option,
        the server attempts to use the value of the <TT
CLASS="ENVAR"
>TZ</TT
>
        environment variable as the default time zone.  If <TT
CLASS="ENVAR"
>TZ</TT
>
        is not defined or is not any of the time zone names known to
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, the server attempts to
        determine the operating system's default time zone by checking the
        behavior of the C library function <TT
CLASS="LITERAL"
>localtime()</TT
>.  The
        default time zone is selected as the closest match among
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s known time zones.
        (These rules are also used to choose the default value of
        <A
HREF="runtime-config-logging.html#GUC-LOG-TIMEZONE"
>log_timezone</A
>, if it is not specified.)
       </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.  This is an alternative spelling
        of <TT
CLASS="COMMAND"
>SET TIMEZONE TO</TT
> with a more SQL-spec-compatible syntax.
       </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
></UL
><P>
    </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
>