1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Make to_timestamp and friends skip leading spaces before an integer field,

even when not in FM mode.  This improves compatibility with Oracle and with
our pre-8.4 behavior, as per bug #4862.

Brendan Jurd

Add a couple of regression test cases for this.  In passing, get rid of the
labeling of the individual test cases; doesn't seem to be good for anything
except causing extra work when inserting a test...

Tom Lane
This commit is contained in:
Tom Lane
2009-06-22 17:54:30 +00:00
parent 18df0ffbd2
commit 3f1e529e78
3 changed files with 157 additions and 120 deletions

View File

@@ -379,68 +379,76 @@ RESET DateStyle;
-- to_timestamp()
--
SELECT '' AS to_timestamp_1, to_timestamp('0097/Feb/16 --> 08:14:30', 'YYYY/Mon/DD --> HH:MI:SS');
SELECT 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 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 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 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 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'HH24 "\\text between quote marks\\"" YY MI SS');
SELECT to_timestamp('15 "text between quote marks" 98 54 45',
E'HH24 "\\text between quote marks\\"" YY MI SS');
SELECT '' AS to_timestamp_7, to_timestamp('05121445482000', 'MMDDHH24MISSYYYY');
SELECT to_timestamp('05121445482000', 'MMDDHH24MISSYYYY');
SELECT '' AS to_timestamp_8, to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
SELECT to_timestamp('2000January09Sunday', 'YYYYFMMonthDDFMDay');
SELECT '' AS to_timestamp_9, to_timestamp('97/Feb/16', 'YYMonDD');
SELECT to_timestamp('97/Feb/16', 'YYMonDD');
SELECT '' AS to_timestamp_10, to_timestamp('19971116', 'YYYYMMDD');
SELECT to_timestamp('19971116', 'YYYYMMDD');
SELECT '' AS to_timestamp_11, to_timestamp('20000-1116', 'YYYY-MMDD');
SELECT to_timestamp('20000-1116', 'YYYY-MMDD');
SELECT '' AS to_timestamp_12, to_timestamp('9-1116', 'Y-MMDD');
SELECT to_timestamp('9-1116', 'Y-MMDD');
SELECT '' AS to_timestamp_13, to_timestamp('95-1116', 'YY-MMDD');
SELECT to_timestamp('95-1116', 'YY-MMDD');
SELECT '' AS to_timestamp_14, to_timestamp('995-1116', 'YYY-MMDD');
SELECT to_timestamp('995-1116', 'YYY-MMDD');
SELECT '' AS to_timestamp_15, to_timestamp('2005426', 'YYYYWWD');
SELECT to_timestamp('2005426', 'YYYYWWD');
SELECT '' AS to_timestamp_16, to_timestamp('2005300', 'YYYYDDD');
SELECT to_timestamp('2005300', 'YYYYDDD');
SELECT '' AS to_timestamp_17, to_timestamp('2005527', 'IYYYIWID');
SELECT to_timestamp('2005527', 'IYYYIWID');
SELECT '' AS to_timestamp_18, to_timestamp('005527', 'IYYIWID');
SELECT to_timestamp('005527', 'IYYIWID');
SELECT '' AS to_timestamp_19, to_timestamp('05527', 'IYIWID');
SELECT to_timestamp('05527', 'IYIWID');
SELECT '' AS to_timestamp_20, to_timestamp('5527', 'IIWID');
SELECT to_timestamp('5527', 'IIWID');
SELECT '' AS to_timestamp_21, to_timestamp('2005364', 'IYYYIDDD');
SELECT to_timestamp('2005364', 'IYYYIDDD');
SELECT to_timestamp('20050302', 'YYYYMMDD');
SELECT to_timestamp('2005 03 02', 'YYYYMMDD');
SELECT to_timestamp(' 2005 03 02', 'YYYYMMDD');
SELECT to_timestamp(' 20050302', 'YYYYMMDD');
--
-- 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');
SELECT to_timestamp('2005527', 'YYYYIWID');
-- Insufficient characters in the source string:
SELECT '' AS to_timestamp_23, to_timestamp('19971', 'YYYYMMDD');
SELECT to_timestamp('19971', 'YYYYMMDD');
-- Insufficient digit characters for a single node:
SELECT '' AS to_timestamp_24, to_timestamp('19971)24', 'YYYYMMDD');
SELECT to_timestamp('19971)24', 'YYYYMMDD');
-- Value clobbering:
SELECT '' AS to_timestamp_25, to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
SELECT to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
-- Non-numeric input:
SELECT '' AS to_timestamp_26, to_timestamp('199711xy', 'YYYYMMDD');
SELECT to_timestamp('199711xy', 'YYYYMMDD');
-- Input that doesn't fit in an int:
SELECT '' AS to_timestamp_27, to_timestamp('10000000000', 'FMYYYY');
SELECT to_timestamp('10000000000', 'FMYYYY');