Postgres Date Order Conventions
-The PGDATESTYLE environment variable used by the backend directly on postmaster startup.
+The PGDATESTYLE environment variable used by the backend directly
+on postmaster startup.
-The PGDATESTYLE environment variable used by the frontend libpq on session startup.
+The PGDATESTYLE environment variable used by the frontend libpq
+on session startup.
-For
Postgres v6.3 (and earlier) the default date/time style is
-"non-European traditional Postgres". In future releases, the default may become ISO-8601, which alleviates
+For
Postgres v6.4 (and earlier)
+the default date/time style is
+"non-European traditional Postgres".
+In future releases, the default may become ISO-8601, which alleviates
date specification ambiguities and Y2K collation problems.
Time Zones
-
Postgres obtains time zone support from the underlying operating system.
-All dates and times are stored internally in Universal Coordinated Time (UTC), alternately known as
-Greenwich Mean Time (GMT). Times are converted to local time on the database server before being
+
Postgres obtains time zone support
+from the underlying operating system.
+All dates and times are stored internally in Universal Coordinated Time (UTC),
+ alternately known as Greenwich Mean Time (GMT).
+Times are converted to local time on the database server before being
sent to the client frontend, hence by default are in the server time zone.
-The PGTZ environment variable set at the client used by libpq to send time zone information to the backend upon connection.
+The PGTZ environment variable set at the client used by libpq
+to send time zone information to the backend upon connection.
-
set timezone SQL sets the time zone for the session.
+The
SQL command
SET TIME ZONE
+sets the time zone for the session.
General-use date and time is input using a wide range of
-styles, including ISO-compatible, SQL-compatible, traditional
+styles, including ISO-compatible,
SQL-compatible,
and other permutations of date and time. In cases where interpretation
-can be ambiguous (quite possible with many traditional styles of date specification)
-
Postgres uses a style setting to resolve the ambiguity.
+can be ambiguous (quite possible with many traditional styles of date
+specification)
Postgres uses a style setting
+to resolve the ambiguity.
Most date and time types share code for data input. For those types
-the input can have any of a wide variety of styles. For numeric date representations,
-European and US conventions can differ, and the proper interpretation is obtained
+the input can have any of a wide variety of styles. For numeric date
+representations,
+European and US conventions can differ, and the proper interpretation
+is obtained
by using the
set datestyle
command before entering data.
-Note that the style setting does not preclude use of various styles for input; it is
+Note that the style setting does not preclude use of various styles for input;
+ it is
used primarily to determine the output style and to resolve ambiguities.
General-use date and time is input using a wide range of
-styles, including ISO-compatible, SQL-compatible, traditional
+styles, including ISO-compatible,
SQL-compatible, traditional
Postgres (see section on "absolute time")
and other permutations of date and time. Output styles can be ISO-compatible,
-SQL-compatible, or traditional
Postgres, with the default set to be compatible
+
SQL-compatible, or traditional
+
Postgres, with the default set to be compatible
General-use time span is input using a wide range of
-syntaxes, including ISO-compatible, SQL-compatible, traditional
+syntaxes, including ISO-compatible,
SQL-compatible,
+traditional
Postgres (see section on "relative time")
and other permutations of time span. Output formats can be ISO-compatible,
-SQL-compatible, or traditional
Postgres, with the default set to be
Postgres-compatible.
+
SQL-compatible, or traditional
+with the default set to be
Postgres-compatible.
Months and years are a "qualitative" time interval, and are stored separately
-from the other "quantitative" time intervals such as day or hour. For date arithmetic,
-the qualitative time units are instantiated in the context of the relevant date or time.
+from the other "quantitative" time intervals such as day or hour.
+For date arithmetic,
+the qualitative time units are instantiated in the context of the
+relevant date or time.
Time span is specified with the following syntax:
abstime
-Absolute time (abstime) is a limited-range (+/- 68 years) and limited-precision (1 sec)
+Absolute time (abstime) is a limited-range (+/- 68 years) and
+limited-precision (1 sec)
date data type. datetime may be preferred, since it
covers a larger range with greater precision.
Valid dates are from Dec 13 20:45:53 1901 GMT to Jan 19 03:14:04
-2038 GMT. As of Version 3.0, times are no longer read and written
+2038 GMT.
+
+
+
Historical Note
+As of Version 3.0, times are no longer read and written
using Greenwich Mean Time; the input and output routines default to
the local time zone.
+
-All special values allowed for datetime are also allowed for "absolute time".
+All special values allowed for datetime are also
+allowed for "absolute time".
Relative time reltime is a limited-range (+/- 68 years)
and limited-precision (1 sec) time span data type.
timespan should be preferred, since it
-covers a larger range with greater precision and, more importantly, can distinguish between
-relative units (months and years) and quantitative units (days, hours, etc). Instead, reltime
-must force months to be exactly 30 days, so time arithmetic does not always work as expected.
-For example, adding one reltime year to abstime today does not produce today's date one year from
+covers a larger range with greater precision and, more importantly,
+can distinguish between
+relative units (months and years) and quantitative units (days, hours, etc).
+Instead, reltime
+must force months to be exactly 30 days, so time arithmetic does not
+always work as expected.
+For example, adding one reltime year to abstime today does not
+produce today's date one year from
now, but rather a date 360 days from today.
-reltime shares input and output routines with the other time span types.
+reltime shares input and output routines with the other
+time span types.
The section on timespan covers this in more detail.
This is currently a limited-range absolute time which closely resembles the
abstime
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 datetime type
-and will move toward SQL92 compliance.
+In future releases this type will absorb the capabilities of the
+datetime type
+and will move toward
SQL92 compliance.
-timestamp is specified using the same syntax as for datetime.
+timestamp is specified using the same syntax as for
+datetime.
interval is an
SQL92 data type which is
-currently mapped to the
timespan Postgres
-data type.
+currently mapped to the timespan
Postgres supports
bool as
-bool can have one of only two states: 'true' or 'false'. A third state, 'unknown', is not
-implemented and is not suggested in
SQL3;
NULL is an
-effective substitute. bool can be used in any boolean expression, and boolean expressions
+bool can have one of only two states: 'true' or 'false'.
+A third state, 'unknown', is not
+implemented and is not suggested in
SQL3;
+effective substitute. bool can be used in any boolean expression,
+and boolean expressions
always evaluate to a result compatible with this type.
Geometric Types
-Geometric types represent two-dimensional spatial objects. The most fundamental type,
+Geometric types represent two-dimensional spatial objects.
+The most fundamental type,
the point, forms the basis for all of the other types.
A rich set of functions and operators is available to perform various geometric
-operations such as scaling, translation, rotation, and determining intersections.
+operations such as scaling, translation, rotation, and determining
+intersections.
Paths are output using the first syntax.
Note that
Postgres versions prior to
-v6.1 used a format for paths which had a single leading parenthesis, a "closed" flag,
+v6.1 used a format for paths which had a single leading parenthesis,
+a "closed" flag,
an integer count of the number of points, then the list of points followed by a
-closing parenthesis. The built-in function upgradepath is supplied to convert
+closing parenthesis.
+The built-in function upgradepath is supplied to convert
paths dumped and reloaded from pre-v6.1 databases.
Polygons are represented by sets of points. Polygons should probably be
-considered
-equivalent to closed paths, but are stored differently and have their own
-set of support routines.
+considered equivalent to closed paths, but are stored differently
+and have their own set of support routines.
Polygons are output using the first syntax.
Note that
Postgres versions prior to
v6.1 used a format for polygons which had a single leading parenthesis, the list
-of x-axis coordinates, the list of y-axis coordinates, followed by a closing parenthesis.
+of x-axis coordinates, the list of y-axis coordinates,
+followed by a closing parenthesis.
The built-in function upgradepoly is supplied to convert
polygons dumped and reloaded from pre-v6.1 databases.