|The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference
by The PostgreSQL Global Development Group
Paperback (6"x9"), 454 pages
RRP £14.95 ($19.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
12.6 Date/Time Input Interpretation
The date/time type inputs are all decoded using the following procedure.
Break the input string into tokens and categorize each token as
a string, time, time zone, or number.
If the numeric token contains a colon (
:), this is a time string. Include all subsequent digits and colons.
If the numeric token contains a dash (
-), slash (
/), or two or more dots (
.), this is a date string which might have a text month. If a date token has already been seen, it is instead interpreted as a time zone name (e.g.,
If the token is numeric only, then it is either a single field
or an ISO 8601 concatenated date (e.g.,
19990113for January 13, 1999) or time (e.g.,
If the token starts with a plus (
+) or minus (
-), then it is either a numeric time zone or a special field.
- If the numeric token contains a colon (
If the token is a text string, match up with possible strings:
- Do a binary-search table lookup for the token as a time zone abbreviation.
If not found, do a similar binary-search table lookup to match
the token as either a special string (e.g.,
today), day (e.g.,
Thursday), month (e.g.,
January), or noise word (e.g.,
- If still not found, throw an error.
When the token is a number or number field:
If there are eight or six digits,
and if no other date fields have been previously read, then interpret
as a “concatenated date” (e.g.,
990118). The interpretation is
- If the token is three digits and a year has already been read, then interpret as day of year.
If four or six digits and a year has already been read, then
interpret as a time (
- If three or more digits and no date fields have yet been found, interpret as a year (this forces yy-mm-dd ordering of the remaining date fields).
Otherwise the date field ordering is assumed to follow the
DateStylesetting: mm-dd-yy, dd-mm-yy, or yy-mm-dd. Throw an error if a month or day field is found to be out of range.
- If there are eight or six digits, and if no other date fields have been previously read, then interpret as a “concatenated date” (e.g.,
- If BC has been specified, negate the year and add one for internal storage. (There is no year zero in the Gregorian calendar, so numerically 1 BC becomes year zero.)
If BC was not specified, and if the year field was two digits in length,
then adjust the year to four digits. If the field is less than 70, then
add 2000, otherwise add 1900.
Tip: Gregorian years AD 1-99 can be entered by using 4 digits with leading zeros (e.g.,
0099is AD 99).
|ISBN 9781906966041||The PostgreSQL 9.0 Reference Manual - Volume 1A - SQL Language Reference||See the print edition|