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

Commit8fc33e6

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 parent600b953 commit8fc33e6

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
@@ -3077,7 +3077,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
30773077
caseDCH_DY:
30783078
caseDCH_Dy:
30793079
caseDCH_dy:
3080-
from_char_seq_search(&value,&s,days,
3080+
from_char_seq_search(&value,&s,days_short,
30813081
n);
30823082
from_char_set_int(&out->d,value,n);
30833083
out->d++;
@@ -3176,10 +3176,6 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
31763176
SKIP_THth(s,n->suffix);
31773177
break;
31783178
caseDCH_RM:
3179-
from_char_seq_search(&value,&s,rm_months_upper,
3180-
n);
3181-
from_char_set_int(&out->mm,MONTHS_PER_YEAR-value,n);
3182-
break;
31833179
caseDCH_rm:
31843180
from_char_seq_search(&value,&s,rm_months_lower,
31853181
n);

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,18 @@ SELECT to_timestamp('20000-1116', 'YYYY-MMDD');
28222822
Thu Nov 16 00:00:00 20000 PST
28232823
(1 row)
28242824

2825+
SELECT to_timestamp('1997 A.D. 11 16', 'YYYY B.C. MM DD');
2826+
to_timestamp
2827+
------------------------------
2828+
Sun Nov 16 00:00:00 1997 PST
2829+
(1 row)
2830+
2831+
SELECT to_timestamp('1997 B.C. 11 16', 'YYYY B.C. MM DD');
2832+
to_timestamp
2833+
---------------------------------
2834+
Tue Nov 16 00:00:00 1997 PST BC
2835+
(1 row)
2836+
28252837
SELECT to_timestamp('9-1116', 'Y-MMDD');
28262838
to_timestamp
28272839
------------------------------
@@ -2906,6 +2918,44 @@ SELECT to_timestamp(' 20050302', 'YYYYMMDD');
29062918
Wed Mar 02 00:00:00 2005 PST
29072919
(1 row)
29082920

2921+
SELECT to_timestamp('2011-12-18 11:38 A.M.', 'YYYY-MM-DD HH12:MI P.M.');
2922+
to_timestamp
2923+
------------------------------
2924+
Sun Dec 18 11:38:00 2011 PST
2925+
(1 row)
2926+
2927+
SELECT to_timestamp('2011-12-18 11:38 P.M.', 'YYYY-MM-DD HH12:MI P.M.');
2928+
to_timestamp
2929+
------------------------------
2930+
Sun Dec 18 23:38:00 2011 PST
2931+
(1 row)
2932+
2933+
SELECT to_timestamp('2011-12-18 11:38 PST', 'YYYY-MM-DD HH12:MI TZ'); -- NYI
2934+
ERROR: "TZ"/"tz"/"OF" format patterns are not supported in to_date
2935+
SELECT to_timestamp('2018-11-02 12:34:56.025', 'YYYY-MM-DD HH24:MI:SS.MS');
2936+
to_timestamp
2937+
----------------------------------
2938+
Fri Nov 02 12:34:56.025 2018 PDT
2939+
(1 row)
2940+
2941+
SELECT to_date('1 4 1902', 'Q MM YYYY'); -- Q is ignored
2942+
to_date
2943+
------------
2944+
04-01-1902
2945+
(1 row)
2946+
2947+
SELECT to_date('3 4 21 01', 'W MM CC YY');
2948+
to_date
2949+
------------
2950+
04-15-2001
2951+
(1 row)
2952+
2953+
SELECT to_date('2458872', 'J');
2954+
to_date
2955+
------------
2956+
01-23-2020
2957+
(1 row)
2958+
29092959
--
29102960
-- Check handling of multiple spaces in format and/or input
29112961
--
@@ -2998,6 +3048,19 @@ SELECT to_timestamp('19971)24', 'YYYYMMDD');
29983048
ERROR: invalid value "1)" for "MM"
29993049
DETAIL: Field requires 2 characters, but only 1 could be parsed.
30003050
HINT: If your source string is not fixed-width, try using the "FM" modifier.
3051+
-- We don't accept full-length day or month names if short form is specified:
3052+
SELECT to_timestamp('Friday 1-January-1999', 'DY DD MON YYYY');
3053+
ERROR: invalid value "ay" for "DD"
3054+
DETAIL: Value must be an integer.
3055+
SELECT to_timestamp('Fri 1-January-1999', 'DY DD MON YYYY');
3056+
ERROR: invalid value "ary-" for "YYYY"
3057+
DETAIL: Value must be an integer.
3058+
SELECT to_timestamp('Fri 1-Jan-1999', 'DY DD MON YYYY'); -- ok
3059+
to_timestamp
3060+
------------------------------
3061+
Fri Jan 01 00:00:00 1999 PST
3062+
(1 row)
3063+
30013064
-- Value clobbering:
30023065
SELECT to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
30033066
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
@@ -412,6 +412,9 @@ SELECT to_timestamp('19971116', 'YYYYMMDD');
412412

413413
SELECT to_timestamp('20000-1116','YYYY-MMDD');
414414

415+
SELECT to_timestamp('1997 A.D. 11 16','YYYY B.C. MM DD');
416+
SELECT to_timestamp('1997 B.C. 11 16','YYYY B.C. MM DD');
417+
415418
SELECT to_timestamp('9-1116','Y-MMDD');
416419

417420
SELECT to_timestamp('95-1116','YY-MMDD');
@@ -440,6 +443,17 @@ SELECT to_timestamp(' 2005 03 02', 'YYYYMMDD');
440443

441444
SELECT to_timestamp(' 20050302','YYYYMMDD');
442445

446+
SELECT to_timestamp('2011-12-18 11:38 A.M.','YYYY-MM-DD HH12:MI P.M.');
447+
SELECT to_timestamp('2011-12-18 11:38 P.M.','YYYY-MM-DD HH12:MI P.M.');
448+
449+
SELECT to_timestamp('2011-12-18 11:38 PST','YYYY-MM-DD HH12:MI TZ');-- NYI
450+
451+
SELECT to_timestamp('2018-11-02 12:34:56.025','YYYY-MM-DD HH24:MI:SS.MS');
452+
453+
SELECT to_date('1 4 1902','Q MM YYYY');-- Q is ignored
454+
SELECT to_date('3 4 21 01','W MM CC YY');
455+
SELECT to_date('2458872','J');
456+
443457
--
444458
-- Check handling of multiple spaces in format and/or input
445459
--
@@ -473,6 +487,11 @@ SELECT to_timestamp('19971', 'YYYYMMDD');
473487
-- Insufficient digit characters for a single node:
474488
SELECT to_timestamp('19971)24','YYYYMMDD');
475489

490+
-- We don't accept full-length day or month names if short form is specified:
491+
SELECT to_timestamp('Friday 1-January-1999','DY DD MON YYYY');
492+
SELECT to_timestamp('Fri 1-January-1999','DY DD MON YYYY');
493+
SELECT to_timestamp('Fri 1-Jan-1999','DY DD MON YYYY');-- ok
494+
476495
-- Value clobbering:
477496
SELECT to_timestamp('1997-11-Jan-16','YYYY-MM-Mon-DD');
478497

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp