Tighten up to_date/to_timestamp so that they are more likely to reject
erroneous input, rather than silently producing bizarre results as formerly happened. Brendan Jurd
This commit is contained in:
parent
70530c808b
commit
06edce4c3f
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.446 2008/09/08 00:47:40 tgl Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.447 2008/09/11 17:32:33 tgl Exp $ -->
|
||||
|
||||
<chapter id="functions">
|
||||
<title>Functions and Operators</title>
|
||||
@ -5187,7 +5187,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Attempting to construct a date using a mixture of ISO week and Gregorian date fields is nonsensical, and could yield unexpected results. In the context of an ISO year, the concept of a 'month' or 'day of month' has no meaning. In the context of a Gregorian year, the ISO week has no meaning. Users should take care to keep Gregorian and ISO date specifications separate.
|
||||
Attempting to construct a date using a mixture of ISO week and
|
||||
Gregorian date fields is nonsensical, and will cause an error. In the
|
||||
context of an ISO year, the concept of a <quote>month</> or <quote>day
|
||||
of month</> has no meaning. In the context of a Gregorian year, the
|
||||
ISO week has no meaning. Users should take care to keep Gregorian and
|
||||
ISO date specifications separate.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2705,3 +2705,160 @@ SELECT '' AS seven, f1 AS european_sql FROM ABSTIME_TBL;
|
||||
(7 rows)
|
||||
|
||||
RESET DateStyle;
|
||||
--
|
||||
-- to_timestamp()
|
||||
--
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
to_timestamp_1 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
to_timestamp_2 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
to_timestamp_3 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Jan 12 00:00:00 1985 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
to_timestamp_4 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun May 16 00:00:00 1976 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
to_timestamp_5 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Aug 21 00:00:00 1582 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
to_timestamp_6 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Thu Jan 01 15:54:45 1998 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
to_timestamp_7 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Fri May 12 14:45:48 2000 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
to_timestamp_8 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun Jan 09 00:00:00 2000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
ERROR: invalid value for "Mon" in source string
|
||||
DETAIL: The given value did not match any of the allowed values for this field.
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
to_timestamp_10 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Nov 16 00:00:00 1997 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
to_timestamp_11 | to_timestamp
|
||||
-----------------+-------------------------------
|
||||
| Thu Nov 16 00:00:00 20000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
to_timestamp_12 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Mon Nov 16 00:00:00 2009 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
to_timestamp_13 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
to_timestamp_14 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
to_timestamp_15 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sat Oct 15 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
to_timestamp_16 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Oct 27 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
to_timestamp_17 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
to_timestamp_18 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
to_timestamp_19 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
to_timestamp_20 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
to_timestamp_21 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- Check errors for some incorrect usages of to_timestamp()
|
||||
--
|
||||
-- Mixture of date conventions (ISO week and Gregorian):
|
||||
SELECT '' AS to_timestamp_22, to_timestamp('2005527', 'YYYYIWID');
|
||||
ERROR: invalid combination of date conventions
|
||||
HINT: Do not mix Gregorian and ISO week date conventions in a formatting template.
|
||||
-- Insufficient characters in the source string:
|
||||
SELECT '' AS to_timestamp_23, to_timestamp('19971', 'YYYYMMDD');
|
||||
ERROR: source string too short for "MM" formatting field
|
||||
DETAIL: Field requires 2 characters, but only 1 remain.
|
||||
HINT: If your source string is not fixed-width, try using the "FM" modifier.
|
||||
-- Insufficient digit characters for a single node:
|
||||
SELECT '' AS to_timestamp_24, to_timestamp('19971)24', 'YYYYMMDD');
|
||||
ERROR: invalid value for "MM" in source string
|
||||
DETAIL: Field requires 2 characters, but only 1 could be parsed.
|
||||
HINT: If your source string is not fixed-width, try using the "FM" modifier.
|
||||
-- Value clobbering:
|
||||
SELECT '' AS to_timestamp_25, to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
|
||||
ERROR: conflicting values for "Mon" field in formatting string
|
||||
DETAIL: This value contradicts a previous setting for the same field type.
|
||||
-- Non-numeric input:
|
||||
SELECT '' AS to_timestamp_26, to_timestamp('199711xy', 'YYYYMMDD');
|
||||
ERROR: invalid value for "DD" in source string
|
||||
DETAIL: Value must be an integer.
|
||||
-- Input that doesn't fit in an int:
|
||||
SELECT '' AS to_timestamp_27, to_timestamp('10000000000', 'FMYYYY');
|
||||
ERROR: value for "YYYY" in source string is out of range
|
||||
DETAIL: Value must be in the range -2147483648 to 2147483647.
|
||||
|
@ -1590,130 +1590,3 @@ SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
|
||||
| 2001 001 01 1 1 1 1
|
||||
(65 rows)
|
||||
|
||||
-- TO_TIMESTAMP()
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
to_timestamp_1 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
to_timestamp_2 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
to_timestamp_3 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Jan 12 00:00:00 1985 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
to_timestamp_4 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun May 16 00:00:00 1976 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
to_timestamp_5 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Aug 21 00:00:00 1582 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
to_timestamp_6 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Thu Jan 01 15:54:45 1998 PST
|
||||
(1 row)
|
||||
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
to_timestamp_7 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Fri May 12 14:45:48 2000 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
to_timestamp_8 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun Jan 09 00:00:00 2000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
ERROR: invalid value for MON/Mon/mon
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
to_timestamp_10 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Nov 16 00:00:00 1997 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
to_timestamp_11 | to_timestamp
|
||||
-----------------+-------------------------------
|
||||
| Thu Nov 16 00:00:00 20000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
to_timestamp_12 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Mon Nov 16 00:00:00 2009 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
to_timestamp_13 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
to_timestamp_14 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
to_timestamp_15 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sat Oct 15 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
to_timestamp_16 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Oct 27 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
to_timestamp_17 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
to_timestamp_18 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
to_timestamp_19 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
to_timestamp_20 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
to_timestamp_21 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SET DateStyle TO DEFAULT;
|
||||
|
@ -1684,131 +1684,3 @@ SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
|
||||
| 2001 001 01 1 1 1 1
|
||||
(66 rows)
|
||||
|
||||
-- TO_TIMESTAMP()
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
to_timestamp_1 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
to_timestamp_2 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Feb 16 08:14:30 0097 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
to_timestamp_3 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Jan 12 00:00:00 1985 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
to_timestamp_4 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun May 16 00:00:00 1976 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
to_timestamp_5 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sat Aug 21 00:00:00 1582 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
to_timestamp_6 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Thu Jan 01 15:54:45 1998 PST
|
||||
(1 row)
|
||||
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
to_timestamp_7 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Fri May 12 14:45:48 2000 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
to_timestamp_8 | to_timestamp
|
||||
----------------+------------------------------
|
||||
| Sun Jan 09 00:00:00 2000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
ERROR: invalid value for MON/Mon/mon
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
to_timestamp_10 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Nov 16 00:00:00 1997 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
to_timestamp_11 | to_timestamp
|
||||
-----------------+-------------------------------
|
||||
| Thu Nov 16 00:00:00 20000 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
to_timestamp_12 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Mon Nov 16 00:00:00 2009 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
to_timestamp_13 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
to_timestamp_14 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Nov 16 00:00:00 1995 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
to_timestamp_15 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sat Oct 15 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
to_timestamp_16 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Thu Oct 27 00:00:00 2005 PDT
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
to_timestamp_17 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
to_timestamp_18 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
to_timestamp_19 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
to_timestamp_20 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
to_timestamp_21 | to_timestamp
|
||||
-----------------+------------------------------
|
||||
| Sun Jan 01 00:00:00 2006 PST
|
||||
(1 row)
|
||||
|
||||
SET DateStyle TO DEFAULT;
|
||||
|
@ -374,3 +374,73 @@ SELECT '' AS "65", d1 AS european_sql FROM TIMESTAMP_TBL;
|
||||
SELECT '' AS seven, f1 AS european_sql FROM ABSTIME_TBL;
|
||||
|
||||
RESET DateStyle;
|
||||
|
||||
--
|
||||
-- to_timestamp()
|
||||
--
|
||||
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
|
||||
--
|
||||
-- Check errors for some incorrect usages of to_timestamp()
|
||||
--
|
||||
|
||||
-- Mixture of date conventions (ISO week and Gregorian):
|
||||
SELECT '' AS to_timestamp_22, to_timestamp('2005527', 'YYYYIWID');
|
||||
|
||||
-- Insufficient characters in the source string:
|
||||
SELECT '' AS to_timestamp_23, to_timestamp('19971', 'YYYYMMDD');
|
||||
|
||||
-- Insufficient digit characters for a single node:
|
||||
SELECT '' AS to_timestamp_24, to_timestamp('19971)24', 'YYYYMMDD');
|
||||
|
||||
-- Value clobbering:
|
||||
SELECT '' AS to_timestamp_25, to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
|
||||
|
||||
-- Non-numeric input:
|
||||
SELECT '' AS to_timestamp_26, to_timestamp('199711xy', 'YYYYMMDD');
|
||||
|
||||
-- Input that doesn't fit in an int:
|
||||
SELECT '' AS to_timestamp_27, to_timestamp('10000000000', 'FMYYYY');
|
||||
|
@ -223,50 +223,3 @@ SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID')
|
||||
|
||||
SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
|
||||
FROM TIMESTAMP_TBL;
|
||||
|
||||
-- TO_TIMESTAMP()
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
|
||||
SET DateStyle TO DEFAULT;
|
||||
|
@ -241,50 +241,3 @@ SELECT '' AS to_char_10, to_char(d1, 'IYYY IYY IY I IW IDDD ID')
|
||||
|
||||
SELECT '' AS to_char_11, to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID')
|
||||
FROM TIMESTAMPTZ_TBL;
|
||||
|
||||
-- TO_TIMESTAMP()
|
||||
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
|
||||
|
||||
SELECT '' AS to_timestamp_2, to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD FMHH:FMMI:FMSS');
|
||||
|
||||
SELECT '' AS to_timestamp_3, to_timestamp('1985 January 12', 'YYYY FMMonth DD');
|
||||
|
||||
SELECT '' AS to_timestamp_4, to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',
|
||||
'"My birthday-> Year" YYYY, "Month:" FMMonth, "Day:" DD');
|
||||
|
||||
SELECT '' AS to_timestamp_5, to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM DD');
|
||||
|
||||
SELECT '' AS to_timestamp_6, to_timestamp('15 "text between quote marks" 98 54 45',
|
||||
E'HH "\\text between quote marks\\"" YY MI SS');
|
||||
|
||||
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHHMISSYYYY');
|
||||
|
||||
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
|
||||
|
||||
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
|
||||
|
||||
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
|
||||
|
||||
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
|
||||
|
||||
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
|
||||
|
||||
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
|
||||
|
||||
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
|
||||
|
||||
SET DateStyle TO DEFAULT;
|
||||
|
Loading…
x
Reference in New Issue
Block a user