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

Commitcb23b84

Browse files
committed
Repair an embarrassingly large number of alphabetization mistakes in the
datetime token tables. Even more embarrassing, the regression testsrevealed some of the problems --- but evidently the bogus output wasn'tquestioned. Add code to postmaster startup to directly check the tablesfor correct ordering, in hopes of not being embarrassed like this again.
1 parent828822b commitcb23b84

File tree

5 files changed

+79
-31
lines changed

5 files changed

+79
-31
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.304 2003/01/07 18:48:13 momjian Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.305 2003/01/16 00:26:44 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -594,6 +594,15 @@ PostmasterMain(int argc, char *argv[])
594594
ExitPostmaster(1);
595595
}
596596

597+
/*
598+
* Other one-time internal sanity checks can go here.
599+
*/
600+
if (!CheckDateTokenTables())
601+
{
602+
postmaster_error("Invalid datetoken tables, please fix.");
603+
ExitPostmaster(1);
604+
}
605+
597606
/*
598607
* Now that we are done processing the postmaster arguments, reset
599608
* getopt(3) library so that it will work correctly in subprocesses.

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

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.97 2002/11/13 17:24:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.98 2003/01/16 00:26:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include"postgres.h"
1616

1717
#include<ctype.h>
18-
#include<math.h>
1918
#include<errno.h>
2019
#include<float.h>
2120
#include<limits.h>
21+
#include<math.h>
2222

2323
#include"miscadmin.h"
24-
#include"utils/guc.h"
2524
#include"utils/datetime.h"
25+
#include"utils/guc.h"
2626

2727

2828
staticintDecodeNumber(intflen,char*field,
@@ -37,7 +37,7 @@ static intDecodeTimezone(char *str, int *tzp);
3737
staticdatetkn*datebsearch(char*key,datetkn*base,unsignedintnel);
3838
staticintDecodeDate(char*str,intfmask,int*tmask,structtm*tm);
3939
staticintDecodePosixTimezone(char*str,int*val);
40-
voidTrimTrailingZeros(char*str);
40+
staticvoidTrimTrailingZeros(char*str);
4141

4242

4343
intday_tab[2][13]= {
@@ -69,14 +69,16 @@ char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
6969
#defineTOVAL(tp,v)((tp)->value = ((v) < 0? NEG((-(v))/15): POS(v)/15))
7070

7171
/*
72-
* datetktbl holds date/time keywords. Note that this table must be strictly
73-
* ordered to allow an O(ln(N)) search algorithm.
72+
* datetktbl holds date/time keywords.
73+
*
74+
* Note that this table must be strictly alphabetically ordered to allow an
75+
* O(ln(N)) search algorithm to be used.
7476
*
75-
* The text field isnot guaranteed to be NULL-terminated.
77+
* The text field isNOT guaranteed to be NULL-terminated.
7678
*
7779
* To keep this table reasonably small, we divide the lexval for TZ and DTZ
7880
* entries by 15 (so they are on 15 minute boundaries) and truncate the text
79-
* field atMAXTOKLEN characters.
81+
* field atTOKMAXLEN characters.
8082
* Formerly, we divided by 10 rather than 15 but there are a few time zones
8183
* which are 30 or 45 minutes away from an even hour, most are on an hour
8284
* boundary, and none on other boundaries.
@@ -88,11 +90,11 @@ char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
8890
staticdatetkndatetktbl[]= {
8991
/*text, token, lexval */
9092
{EARLY,RESERV,DTK_EARLY},/* "-infinity" reserved for "early time" */
93+
{"abstime",IGNORE_DTF,0},/* for pre-v6.1 "Invalid Abstime" */
9194
{"acsst",DTZ,POS(42)},/* Cent. Australia */
9295
{"acst",DTZ,NEG(16)},/* Atlantic/Porto Acre */
9396
{"act",TZ,NEG(20)},/* Atlantic/Porto Acre */
9497
{DA_D,ADBC,AD},/* "ad" for years >= 0 */
95-
{"abstime",IGNORE_DTF,0},/* for pre-v6.1 "Invalid Abstime" */
9698
{"adt",DTZ,NEG(12)},/* Atlantic Daylight Time */
9799
{"aesst",DTZ,POS(44)},/* E. Australia */
98100
{"aest",TZ,POS(40)},/* Australia Eastern Std Time */
@@ -101,16 +103,18 @@ static datetkn datetktbl[] = {
101103
{"akdt",DTZ,NEG(32)},/* Alaska Daylight Time */
102104
{"akst",DTZ,NEG(36)},/* Alaska Standard Time */
103105
{"allballs",RESERV,DTK_ZULU},/* 00:00:00 */
104-
{"almt",TZ,POS(24)},/* Almaty Time */
105106
{"almst",TZ,POS(28)},/* Almaty Savings Time */
107+
{"almt",TZ,POS(24)},/* Almaty Time */
106108
{"am",AMPM,AM},
107109
{"amst",DTZ,POS(20)},/* Armenia Summer Time (Yerevan) */
108-
{"amt",TZ,POS(16)},/* Armenia Time (Yerevan) */
109110
#if0
110111
{"amst",DTZ,NEG(12)},/* Porto Velho */
111112
#endif
113+
{"amt",TZ,POS(16)},/* Armenia Time (Yerevan) */
112114
{"anast",DTZ,POS(52)},/* Anadyr Summer Time (Russia) */
113115
{"anat",TZ,POS(48)},/* Anadyr Time (Russia) */
116+
{"apr",MONTH,4},
117+
{"april",MONTH,4},
114118
#if0
115119
aqtst
116120
aqtt
@@ -122,8 +126,6 @@ static datetkn datetktbl[] = {
122126
ast/* Atlantic Standard Time, Arabia Standard
123127
* Time, Acre Standard Time */
124128
#endif
125-
{"apr",MONTH,4},
126-
{"april",MONTH,4},
127129
{"ast",TZ,NEG(16)},/* Atlantic Std Time (Canada) */
128130
{"at",IGNORE_DTF,0},/* "at" (throwaway) */
129131
{"aug",MONTH,8},
@@ -181,12 +183,12 @@ static datetkn datetktbl[] = {
181183
#endif
182184
{"cot",TZ,NEG(20)},/* Columbia Time */
183185
{"cst",TZ,NEG(24)},/* Central Standard Time */
186+
{DCURRENT,RESERV,DTK_CURRENT},/* "current" is always now */
184187
#if0
185188
cvst
186189
#endif
187190
{"cvt",TZ,POS(28)},/* Christmas Island Time (Indian Ocean) */
188191
{"cxt",TZ,POS(28)},/* Christmas Island Time (Indian Ocean) */
189-
{DCURRENT,RESERV,DTK_CURRENT},/* "current" is always now */
190192
{"d",UNITS,DTK_DAY},/* "day of month" for ISO input */
191193
{"davt",TZ,POS(28)},/* Davis Time (Antarctica) */
192194
{"ddut",TZ,POS(40)},/* Dumont-d'Urville Time (Antarctica) */
@@ -414,8 +416,8 @@ static datetkn datetktbl[] = {
414416
syot
415417
#endif
416418
{"t",ISOTIME,DTK_TIME},/* Filler for ISO time fields */
417-
{"that",TZ,NEG(40)},/* Tahiti Time */
418419
{"tft",TZ,POS(20)},/* Kerguelen Time */
420+
{"that",TZ,NEG(40)},/* Tahiti Time */
419421
{"thu",DOW,4},
420422
{"thur",DOW,4},
421423
{"thurs",DOW,4},
@@ -516,9 +518,9 @@ static datetkn deltatktbl[] = {
516518
{DDAY,UNITS,DTK_DAY},/* "day" relative */
517519
{"days",UNITS,DTK_DAY},/* "days" relative */
518520
{"dec",UNITS,DTK_DECADE},/* "decade" relative */
519-
{"decs",UNITS,DTK_DECADE},/* "decades" relative */
520521
{DDECADE,UNITS,DTK_DECADE},/* "decade" relative */
521522
{"decades",UNITS,DTK_DECADE},/* "decades" relative */
523+
{"decs",UNITS,DTK_DECADE},/* "decades" relative */
522524
{"h",UNITS,DTK_HOUR},/* "hour" relative */
523525
{DHOUR,UNITS,DTK_HOUR},/* "hour" relative */
524526
{"hours",UNITS,DTK_HOUR},/* "hours" relative */
@@ -534,7 +536,6 @@ static datetkn deltatktbl[] = {
534536
{"mils",UNITS,DTK_MILLENNIUM},/* "millennia" relative */
535537
{"min",UNITS,DTK_MINUTE},/* "minute" relative */
536538
{"mins",UNITS,DTK_MINUTE},/* "minutes" relative */
537-
{"mins",UNITS,DTK_MINUTE},/* "minutes" relative */
538539
{DMINUTE,UNITS,DTK_MINUTE},/* "minute" relative */
539540
{"minutes",UNITS,DTK_MINUTE},/* "minutes" relative */
540541
{"mon",UNITS,DTK_MONTH},/* "months" relative */
@@ -555,7 +556,6 @@ static datetkn deltatktbl[] = {
555556
{"seconds",UNITS,DTK_SECOND},
556557
{"secs",UNITS,DTK_SECOND},
557558
{DTIMEZONE,UNITS,DTK_TZ},/* "timezone" time offset */
558-
{"timezone",UNITS,DTK_TZ},/* "timezone" time offset */
559559
{"timezone_h",UNITS,DTK_TZ_HOUR},/* timezone hour units */
560560
{"timezone_m",UNITS,DTK_TZ_MINUTE},/* timezone minutes units */
561561
{"undefined",RESERV,DTK_INVALID},/* pre-v6.1 invalid time */
@@ -576,9 +576,9 @@ static datetkn deltatktbl[] = {
576576

577577
staticunsignedintszdeltatktbl=sizeofdeltatktbl /sizeofdeltatktbl[0];
578578

579-
datetkn*datecache[MAXDATEFIELDS]= {NULL};
579+
staticdatetkn*datecache[MAXDATEFIELDS]= {NULL};
580580

581-
datetkn*deltacache[MAXDATEFIELDS]= {NULL};
581+
staticdatetkn*deltacache[MAXDATEFIELDS]= {NULL};
582582

583583

584584
/*
@@ -653,7 +653,7 @@ j2day(int date)
653653
/* TrimTrailingZeros()
654654
* ... resulting from printing numbers with full precision.
655655
*/
656-
void
656+
staticvoid
657657
TrimTrailingZeros(char*str)
658658
{
659659
intlen=strlen(str);
@@ -3690,3 +3690,40 @@ ClearDateCache(bool newval, bool doit, bool interactive)
36903690

36913691
return true;
36923692
}
3693+
3694+
/*
3695+
* We've been burnt by stupid errors in the ordering of the datetkn tables
3696+
* once too often. Arrange to check them during postmaster start.
3697+
*/
3698+
staticbool
3699+
CheckDateTokenTable(constchar*tablename,datetkn*base,unsignedintnel)
3700+
{
3701+
boolok= true;
3702+
unsignedinti;
3703+
3704+
for (i=1;i<nel;i++)
3705+
{
3706+
if (strncmp(base[i-1].token,base[i].token,TOKMAXLEN) >=0)
3707+
{
3708+
elog(LOG,"Ordering error in %s table: \"%.*s\" >= \"%.*s\"",
3709+
tablename,
3710+
TOKMAXLEN,base[i-1].token,
3711+
TOKMAXLEN,base[i].token);
3712+
ok= false;
3713+
}
3714+
}
3715+
returnok;
3716+
}
3717+
3718+
bool
3719+
CheckDateTokenTables(void)
3720+
{
3721+
boolok= true;
3722+
3723+
ok &=CheckDateTokenTable("datetktbl",datetktbl,szdatetktbl);
3724+
ok &=CheckDateTokenTable("deltatktbl",deltatktbl,szdeltatktbl);
3725+
ok &=CheckDateTokenTable("australian_datetktbl",
3726+
australian_datetktbl,
3727+
australian_szdatetktbl);
3728+
returnok;
3729+
}

‎src/include/utils/datetime.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: datetime.h,v 1.33 2002/09/04 20:31:45 momjian Exp $
12+
* $Id: datetime.h,v 1.34 2003/01/16 00:26:49 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616
#ifndefDATETIME_H
1717
#defineDATETIME_H
1818

19-
#include<time.h>
20-
#include<math.h>
2119
#include<limits.h>
20+
#include<math.h>
21+
#include<time.h>
2222

2323
#include"utils/timestamp.h"
2424

@@ -293,4 +293,6 @@ extern bool ClearDateCache(bool, bool, bool);
293293

294294
externintj2day(intjd);
295295

296+
externboolCheckDateTokenTables(void);
297+
296298
#endif/* DATETIME_H */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CREATE TABLE TIMESTAMP_TBL ( d1 timestamp(2) without time zone);
1111
-- statements.
1212
INSERT INTO TIMESTAMP_TBL VALUES ('now');
1313
INSERT INTO TIMESTAMP_TBL VALUES ('current');
14-
ERROR:Bad timestamp external representation 'current'
14+
ERROR:'CURRENT' is no longer supported
1515
INSERT INTO TIMESTAMP_TBL VALUES ('today');
1616
INSERT INTO TIMESTAMP_TBL VALUES ('yesterday');
1717
INSERT INTO TIMESTAMP_TBL VALUES ('tomorrow');
@@ -64,9 +64,9 @@ ERROR: TIMESTAMP 'invalid' no longer supported
6464
-- Postgres v6.0 standard output format
6565
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
6666
INSERT INTO TIMESTAMP_TBL VALUES ('Invalid Abstime');
67-
ERROR:Bad timestamp external representation'Invalid Abstime'
67+
ERROR:TIMESTAMP'Invalid Abstime' no longer supported
6868
INSERT INTO TIMESTAMP_TBL VALUES ('Undefined Abstime');
69-
ERROR:Bad timestamp external representation'Undefined Abstime'
69+
ERROR:TIMESTAMP'Undefined Abstime' no longer supported
7070
-- Variations on Postgres v6.1 standard output format
7171
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
7272
INSERT INTO TIMESTAMP_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SET australian_timezones = 'off';
66
CREATE TABLE TIMESTAMPTZ_TBL ( d1 timestamp(2) with time zone);
77
INSERT INTO TIMESTAMPTZ_TBL VALUES ('now');
88
INSERT INTO TIMESTAMPTZ_TBL VALUES ('current');
9-
ERROR:Bad timestamp external representation 'current'
9+
ERROR:'CURRENT' is no longer supported
1010
INSERT INTO TIMESTAMPTZ_TBL VALUES ('today');
1111
INSERT INTO TIMESTAMPTZ_TBL VALUES ('yesterday');
1212
INSERT INTO TIMESTAMPTZ_TBL VALUES ('tomorrow');
@@ -59,9 +59,9 @@ ERROR: TIMESTAMP WITH TIME ZONE 'invalid' no longer supported
5959
-- Postgres v6.0 standard output format
6060
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01 1997 PST');
6161
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Invalid Abstime');
62-
ERROR:Bad timestamp external representation 'Invalid Abstime'
62+
ERROR:TIMESTAMP WITH TIME ZONE 'Invalid Abstime' no longer supported
6363
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Undefined Abstime');
64-
ERROR:Bad timestamp external representation 'Undefined Abstime'
64+
ERROR:TIMESTAMP WITH TIME ZONE 'Undefined Abstime' no longer supported
6565
-- Variations on Postgres v6.1 standard output format
6666
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.000001 1997 PST');
6767
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Mon Feb 10 17:32:01.999999 1997 PST');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp