|
- timestamp
+ timestamp without time zone
both date and time
8 bytes
4713 BC
|
timestamp [ with time zone ]
- date and time with time zone
+ both date and time
8 bytes
- 1903 AD
- 2037 AD
+ 4713 BC
+ AD 1465001
1 microsecond / 14 digits
|
- To ensure compatibility to earlier versions of
Postgres
- we also continue to provide datetime (equivalent to timestamp) and
- timespan (equivalent to interval),
- however support for these is now restricted to having an
- implicit translation to timestamp and
- interval.
- The types abstime
- and reltime are lower precision types which are used internally.
- You are discouraged from using any of 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.
+ Time zones, and time zone conventions, are influenced by
+ political conventions, not just physical effects. Time zones have
+ become somewhat standardized during the 1900's, but continue to
+ be prone to arbitrary changes with time.
+
PostgreSQL uses your operating
+ system's underlying features to provide 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).
+ timestamp with time zone will use time zone
+ information only within that year range, and assumes that times
+ are in UTC outside that range.
+ To ensure compatibility to earlier versions of
Postgres
+ we also continue to provide datetime
+ (equivalent to timestamp) and
+ timespan (equivalent to interval),
+ however support for these is now restricted to having an
+ implicit translation to timestamp and
+ interval.
+ The types abstime
+ and reltime are lower precision types which are used internally.
+ You are discouraged from using any of 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.
+
Date/Time Input
data type
+
+ time
+
Per SQL99, this type can be referenced as time and
time with time zone
+
+ data type
+
+
+ data type
+
+
This type is defined by SQL92, but the definition exhibits
- fundamental deficiencies that render the type nearly useless. In
+ properties which lead to questionable usefulness. In
most cases, a combination of date,
- time, and timestamp
+ time, timestamp without time zone
+ and timestamp with time zone
should provide a complete range of date/time functionality
required by any application.
-
timestamp
+
timestamp without time zone
+
+
+
timestamp without time zone
+ data type
+
+
+ Valid input for the timestamp without time zone
+ type consists of a concatenation
+ of a date and a time, followed by an optional AD or
+ BC, followed by an optional time zone. (See below.)
+ Thus
+
+1999-01-08 04:05:06
+
+
+ is a valid timestamp without time zone value that
+ In addition, the wide-spread format
+
+January 8 04:05:06 1999 PST
+
+ is supported.
+
+
+ For timestamp without time zone, any explicit time
+ zone specified in the input is silently swallowed. 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.
+
+
+
+
+
timestamp with time zone
+
|
epoch
1970-01-01 00:00:00+00 (Unix system time zero)
-
Postgres must have internal tabular
+
Postgres contains internal tabular
information for time zone decoding, since there is no *nix standard
system interface to provide access to general, cross-timezone
information. The underlying OS is used to
-
+
Functions and Operators
the functions and operators described in this chapter, with the
exception of the most trivial arithmetic and comparison operators
and some explicitly marked functions, are not specified by the
SQL
- standard. However, many other
RDBMS packages provide a lot of the
- same or similar functions, and some of the ones provided in
-
Postgres have in fact been inspired by
- other implementations.
+ standard. Some of this extended functionality is present in other
+
RDBMS products, and in many cases this
+ functionality is compatible and consistant between various products.
Mathematical Functions and Operators
+ Mathematical operators are provided for many
+
PostgreSQL types. For types without
+ common mathematical conventions for all possible permutations
+ (e.g. date/time types) we
+ describe the actual behavior in subsequent sections.
+
+
-
Mathematical OperatorsTITLE>
+
Mathematical Operatorstitle>
-
Formatting Functions
+
Multi-type Formatting Functions
-
Date/Time Functions
+
Date/Time Functions and Operators
shows the available
- functions for date/time value processing. The basic arithmetic
- operators (+, *, etc.) are
- also available. For formatting functions, refer to
+ functions for date/time value processing.
+ illustrates the
+ behaviors of the basic arithmetic
+ operators (+, *, etc.).
+ For formatting functions, refer to
linkend="functions-formatting">. You should be familiar with the
background information on date/time data types (see
linkend="datatype-datetime">).
+ The date/time operators described below behave similarly for types
+ involving time zones as well as those without.
+
+
+
Date/Time Operators
+
+
+
+ |
+ Name
+ Example
+ Result
+
+
+
+
+ |
+ +
+ timestamp '2001-09-28 01:00' + interval '23 hours'
+ timestamp '2001-09-29 00:00'
+
+
+ |
+ +
+ date '2001-09-28' + interval '1 hour'
+ timestamp '2001-09-28 01:00'
+
+
+ |
+ +
+ time '01:00' + interval '3 hours'
+ time '04:00'
+
+
+ |
+ -
+ timestamp '2001-09-28 23:00' - interval '23 hours'
+ timestamp '2001-09-28'
+
+
+ |
+ -
+ date '2001-09-28' + interval '1 hour'
+ timestamp '2001-09-27 23:00'
+
+
+ |
+ -
+ time '05:00' + interval '2 hours'
+ time '03:00'
+
+
+ |
+ -
+ interval '2 hours' - time '05:00'
+ time '03:00:00'
+
+
+ |
+ *
+ interval '1 hour' * int '3'
+ interval '03:00'
+
+
+ |
+ /
+ interval '1 hour' / int '3'
+ interval '00:20'
+
+
+
+
+
+
+ The date/time functions are summarized below, with additional
+ details in subsequent sections.
+
-
+
EXTRACT, date_part
For date and timestamp values, the
- number of seconds since 1970-01-01 00:00:00 (Result may be
+ number of seconds since 1970-01-01 00:00:00-00 (Result may be
negative.); for interval values, the total number
of seconds in the interval
Database Creation
- Databases are created by the create database issued from
+ Databases are created by the CREATE DATABASE issued from
within
Postgres.
createdb is a command-line
utility provided to give the same functionality from outside
Postgres.
-<Chapter Id="recovery">
-Database Recoveryitle>
+<chapter Id="failure">
+ Database Failuresitle>
-This section needs to be written. Volunteers?
-
+ Database failures (or the possibility of such) must be assumed to be
+ lurking, ready to strike at some time in the future. A prudent
+ database administrator will plan for the inevitability of failures
+ of all possible kinds, and will have appropriate plans and
+ procedures in place before the failure occurs.
+
-
+ Database recovery is necessary in the event of hardware or software
+ failure. There are several categories of failures; some of these
+ require relatively minor adjustments to the database, while others
+ may depend on the existance of previously prepared database dumps
+ and other recovery data sets. It should be emphasized that if your
+ data is important and/or difficult to regenerate, then you should
+ have considered and prepared for various failure scenarios.
+
+
+
+
Disk Filled
+
+ A filled data disk may result in subsequent corruption of database
+ indices, but not of the fundamental data tables. If the WAL files
+ are on the same disk (as is the case for a default configuration)
+ then a filled disk during database initialization may result in
+ corrupted or incomplete WAL files. This failure condition is
+ detected and the database will refuse to start up. You must free
+ up additional space on the disk (or move the WAL area to another
+ disk; see ) and then restart the
+
postmaster to recover from this condition.
+
+
+
+
+
Disk Failed
+
+ Failure of any disk (or of a logical storage device such as a RAID
+ subsystem) involved with an active database will require
+ that the database be recovered from a previously prepared database
+ dump. This dump must be prepared using
+
pg_dumpall, and updates to the database
+ occuring after the database installation was dumped will be lost.
+
+
+
+
+
File Corrupted
+
+
+
+
+
+
Table Corrupted
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Database Recovery
+
+ Database recovery is necessary in the event of hardware or software
+ failure. There are several categories of failures; some of these
+ require relatively minor adjustments to the database, while others
+ may depend on the existance of previously prepared database dumps
+ and other recovery data sets. It should be emphasized that if your
+ data is important and/or difficult to regenerate, then you should
+ have considered and prepared for various failure scenarios.
+
+
+
+
+
+