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

Commitd6a9548

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 parent212b870 commitd6a9548

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
@@ -3128,7 +3128,7 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
31283128
caseDCH_DY:
31293129
caseDCH_Dy:
31303130
caseDCH_dy:
3131-
from_char_seq_search(&value,&s,days,
3131+
from_char_seq_search(&value,&s,days_short,
31323132
n);
31333133
from_char_set_int(&out->d,value,n);
31343134
out->d++;
@@ -3227,10 +3227,6 @@ DCH_from_char(FormatNode *node, const char *in, TmFromChar *out)
32273227
SKIP_THth(s,n->suffix);
32283228
break;
32293229
caseDCH_RM:
3230-
from_char_seq_search(&value,&s,rm_months_upper,
3231-
n);
3232-
from_char_set_int(&out->mm,MONTHS_PER_YEAR-value,n);
3233-
break;
32343230
caseDCH_rm:
32353231
from_char_seq_search(&value,&s,rm_months_lower,
32363232
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,44 @@ 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+
2957+
SELECT to_timestamp('2011-12-18 11:38 PST', 'YYYY-MM-DD HH12:MI TZ'); -- NYI
2958+
ERROR: formatting field "TZ" is only supported in to_char
2959+
SELECT to_timestamp('2018-11-02 12:34:56.025', 'YYYY-MM-DD HH24:MI:SS.MS');
2960+
to_timestamp
2961+
----------------------------------
2962+
Fri Nov 02 12:34:56.025 2018 PDT
2963+
(1 row)
2964+
2965+
SELECT to_date('1 4 1902', 'Q MM YYYY'); -- Q is ignored
2966+
to_date
2967+
------------
2968+
04-01-1902
2969+
(1 row)
2970+
2971+
SELECT to_date('3 4 21 01', 'W MM CC YY');
2972+
to_date
2973+
------------
2974+
04-15-2001
2975+
(1 row)
2976+
2977+
SELECT to_date('2458872', 'J');
2978+
to_date
2979+
------------
2980+
01-23-2020
2981+
(1 row)
2982+
29332983
--
29342984
-- Check handling of multiple spaces in format and/or input
29352985
--
@@ -3022,6 +3072,19 @@ SELECT to_timestamp('19971)24', 'YYYYMMDD');
30223072
ERROR: invalid value "1)" for "MM"
30233073
DETAIL: Field requires 2 characters, but only 1 could be parsed.
30243074
HINT: If your source string is not fixed-width, try using the "FM" modifier.
3075+
-- We don't accept full-length day or month names if short form is specified:
3076+
SELECT to_timestamp('Friday 1-January-1999', 'DY DD MON YYYY');
3077+
ERROR: invalid value "ay" for "DD"
3078+
DETAIL: Value must be an integer.
3079+
SELECT to_timestamp('Fri 1-January-1999', 'DY DD MON YYYY');
3080+
ERROR: invalid value "ary-" for "YYYY"
3081+
DETAIL: Value must be an integer.
3082+
SELECT to_timestamp('Fri 1-Jan-1999', 'DY DD MON YYYY'); -- ok
3083+
to_timestamp
3084+
------------------------------
3085+
Fri Jan 01 00:00:00 1999 PST
3086+
(1 row)
3087+
30253088
-- Value clobbering:
30263089
SELECT to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
30273090
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,6 +449,17 @@ 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+
455+
SELECT to_timestamp('2011-12-18 11:38 PST','YYYY-MM-DD HH12:MI TZ');-- NYI
456+
457+
SELECT to_timestamp('2018-11-02 12:34:56.025','YYYY-MM-DD HH24:MI:SS.MS');
458+
459+
SELECT to_date('1 4 1902','Q MM YYYY');-- Q is ignored
460+
SELECT to_date('3 4 21 01','W MM CC YY');
461+
SELECT to_date('2458872','J');
462+
449463
--
450464
-- Check handling of multiple spaces in format and/or input
451465
--
@@ -479,6 +493,11 @@ SELECT to_timestamp('19971', 'YYYYMMDD');
479493
-- Insufficient digit characters for a single node:
480494
SELECT to_timestamp('19971)24','YYYYMMDD');
481495

496+
-- We don't accept full-length day or month names if short form is specified:
497+
SELECT to_timestamp('Friday 1-January-1999','DY DD MON YYYY');
498+
SELECT to_timestamp('Fri 1-January-1999','DY DD MON YYYY');
499+
SELECT to_timestamp('Fri 1-Jan-1999','DY DD MON YYYY');-- ok
500+
482501
-- Value clobbering:
483502
SELECT to_timestamp('1997-11-Jan-16','YYYY-MM-Mon-DD');
484503

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp