Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a9fef2

Browse files
committed
Fix an oversight in commit4c70098.
I had supposed that the from_char_seq_search() call sites wereall passing the constant arrays you'd expect them to pass ...but on looking closer, the one for DY format was passing thedays[] array not days_short[]. This accidentally worked becausethe day abbreviations in English are all the same as the firstthree letters of the full day names. However, once we took outthe "maximum comparison length" logic, it stopped working.As penance for that oversight, add regression test cases coveringthis, as well as every other switch case in DCH_from_char() thatwas not reached according to the code coverage report.Also, fold the DCH_RM and DCH_rm cases into one --- now thatseq_search is case independent, there's no need to pass differentcomparison arrays for those cases.Back-patch, as the previous commit was.
1 parentfb12aef commit7a9fef2

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

‎src/backend/utils/adt/formatting.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,7 +3140,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
31403140
caseDCH_DY:
31413141
caseDCH_Dy:
31423142
caseDCH_dy:
3143-
from_char_seq_search(&value,&s,days,
3143+
from_char_seq_search(&value,&s,days_short,
31443144
n);
31453145
from_char_set_int(&out->d,value,n);
31463146
out->d++;
@@ -3239,10 +3239,6 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
32393239
SKIP_THth(s,n->suffix);
32403240
break;
32413241
caseDCH_RM:
3242-
from_char_seq_search(&value,&s,rm_months_upper,
3243-
n);
3244-
from_char_set_int(&out->mm,MONTHS_PER_YEAR-value,n);
3245-
break;
32463242
caseDCH_rm:
32473243
from_char_seq_search(&value,&s,rm_months_lower,
32483244
n);

‎src/test/regress/expected/horology.out‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,18 @@ SELECT to_timestamp('1997 BC 11 16', 'YYYY BC MM DD');
28342834
Tue Nov 16 00:00:00 1997 PST BC
28352835
(1 row)
28362836

2837+
SELECT to_timestamp('1997 A.D. 11 16', 'YYYY B.C. MM DD');
2838+
to_timestamp
2839+
------------------------------
2840+
Sun Nov 16 00:00:00 1997 PST
2841+
(1 row)
2842+
2843+
SELECT to_timestamp('1997 B.C. 11 16', 'YYYY B.C. MM DD');
2844+
to_timestamp
2845+
---------------------------------
2846+
Tue Nov 16 00:00:00 1997 PST BC
2847+
(1 row)
2848+
28372849
SELECT to_timestamp('9-1116', 'Y-MMDD');
28382850
to_timestamp
28392851
------------------------------
@@ -2930,6 +2942,18 @@ SELECT to_timestamp('2011-12-18 11:38 PM', 'YYYY-MM-DD HH12:MI PM');
29302942
Sun Dec 18 23:38:00 2011 PST
29312943
(1 row)
29322944

2945+
SELECT to_timestamp('2011-12-18 11:38 A.M.', 'YYYY-MM-DD HH12:MI P.M.');
2946+
to_timestamp
2947+
------------------------------
2948+
Sun Dec 18 11:38:00 2011 PST
2949+
(1 row)
2950+
2951+
SELECT to_timestamp('2011-12-18 11:38 P.M.', 'YYYY-MM-DD HH12:MI P.M.');
2952+
to_timestamp
2953+
------------------------------
2954+
Sun Dec 18 23:38:00 2011 PST
2955+
(1 row)
2956+
29332957
SELECT to_timestamp('2011-12-18 11:38 +05', 'YYYY-MM-DD HH12:MI TZH');
29342958
to_timestamp
29352959
------------------------------
@@ -2960,6 +2984,32 @@ SELECT to_timestamp('2011-12-18 11:38 20', 'YYYY-MM-DD HH12:MI TZM');
29602984
Sun Dec 18 03:18:00 2011 PST
29612985
(1 row)
29622986

2987+
SELECT to_timestamp('2011-12-18 11:38 PST', 'YYYY-MM-DD HH12:MI TZ'); -- NYI
2988+
ERROR: formatting field "TZ" is only supported in to_char
2989+
SELECT to_timestamp('2018-11-02 12:34:56.025', 'YYYY-MM-DD HH24:MI:SS.MS');
2990+
to_timestamp
2991+
----------------------------------
2992+
Fri Nov 02 12:34:56.025 2018 PDT
2993+
(1 row)
2994+
2995+
SELECT to_date('1 4 1902', 'Q MM YYYY'); -- Q is ignored
2996+
to_date
2997+
------------
2998+
04-01-1902
2999+
(1 row)
3000+
3001+
SELECT to_date('3 4 21 01', 'W MM CC YY');
3002+
to_date
3003+
------------
3004+
04-15-2001
3005+
(1 row)
3006+
3007+
SELECT to_date('2458872', 'J');
3008+
to_date
3009+
------------
3010+
01-23-2020
3011+
(1 row)
3012+
29633013
--
29643014
-- Check handling of multiple spaces in format and/or input
29653015
--
@@ -3052,6 +3102,19 @@ SELECT to_timestamp('19971)24', 'YYYYMMDD');
30523102
ERROR: invalid value "1)" for "MM"
30533103
DETAIL: Field requires 2 characters, but only 1 could be parsed.
30543104
HINT: If your source string is not fixed-width, try using the "FM" modifier.
3105+
-- We don't accept full-length day or month names if short form is specified:
3106+
SELECT to_timestamp('Friday 1-January-1999', 'DY DD MON YYYY');
3107+
ERROR: invalid value "ay" for "DD"
3108+
DETAIL: Value must be an integer.
3109+
SELECT to_timestamp('Fri 1-January-1999', 'DY DD MON YYYY');
3110+
ERROR: invalid value "ary-" for "YYYY"
3111+
DETAIL: Value must be an integer.
3112+
SELECT to_timestamp('Fri 1-Jan-1999', 'DY DD MON YYYY'); -- ok
3113+
to_timestamp
3114+
------------------------------
3115+
Fri Jan 01 00:00:00 1999 PST
3116+
(1 row)
3117+
30553118
-- Value clobbering:
30563119
SELECT to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
30573120
ERROR: conflicting values for "Mon" field in formatting string

‎src/test/regress/sql/horology.sql‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ SELECT to_timestamp('20000-1116', 'YYYY-MMDD');
415415
SELECT to_timestamp('1997 AD 11 16','YYYY BC MM DD');
416416
SELECT to_timestamp('1997 BC 11 16','YYYY BC MM DD');
417417

418+
SELECT to_timestamp('1997 A.D. 11 16','YYYY B.C. MM DD');
419+
SELECT to_timestamp('1997 B.C. 11 16','YYYY B.C. MM DD');
420+
418421
SELECT to_timestamp('9-1116','Y-MMDD');
419422

420423
SELECT to_timestamp('95-1116','YY-MMDD');
@@ -446,12 +449,23 @@ SELECT to_timestamp(' 20050302', 'YYYYMMDD');
446449
SELECT to_timestamp('2011-12-18 11:38 AM','YYYY-MM-DD HH12:MI PM');
447450
SELECT to_timestamp('2011-12-18 11:38 PM','YYYY-MM-DD HH12:MI PM');
448451

452+
SELECT to_timestamp('2011-12-18 11:38 A.M.','YYYY-MM-DD HH12:MI P.M.');
453+
SELECT to_timestamp('2011-12-18 11:38 P.M.','YYYY-MM-DD HH12:MI P.M.');
454+
449455
SELECT to_timestamp('2011-12-18 11:38 +05','YYYY-MM-DD HH12:MI TZH');
450456
SELECT to_timestamp('2011-12-18 11:38 -05','YYYY-MM-DD HH12:MI TZH');
451457
SELECT to_timestamp('2011-12-18 11:38 +05:20','YYYY-MM-DD HH12:MI TZH:TZM');
452458
SELECT to_timestamp('2011-12-18 11:38 -05:20','YYYY-MM-DD HH12:MI TZH:TZM');
453459
SELECT to_timestamp('2011-12-18 11:38 20','YYYY-MM-DD HH12:MI TZM');
454460

461+
SELECT to_timestamp('2011-12-18 11:38 PST','YYYY-MM-DD HH12:MI TZ');-- NYI
462+
463+
SELECT to_timestamp('2018-11-02 12:34:56.025','YYYY-MM-DD HH24:MI:SS.MS');
464+
465+
SELECT to_date('1 4 1902','Q MM YYYY');-- Q is ignored
466+
SELECT to_date('3 4 21 01','W MM CC YY');
467+
SELECT to_date('2458872','J');
468+
455469
--
456470
-- Check handling of multiple spaces in format and/or input
457471
--
@@ -485,6 +499,11 @@ SELECT to_timestamp('19971', 'YYYYMMDD');
485499
-- Insufficient digit characters for a single node:
486500
SELECT to_timestamp('19971)24','YYYYMMDD');
487501

502+
-- We don't accept full-length day or month names if short form is specified:
503+
SELECT to_timestamp('Friday 1-January-1999','DY DD MON YYYY');
504+
SELECT to_timestamp('Fri 1-January-1999','DY DD MON YYYY');
505+
SELECT to_timestamp('Fri 1-Jan-1999','DY DD MON YYYY');-- ok
506+
488507
-- Value clobbering:
489508
SELECT to_timestamp('1997-11-Jan-16','YYYY-MM-Mon-DD');
490509

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp