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

Commit4b16049

Browse files
committed
Clean up error messages related to bad datetime units.
Adjust the error texts used for unrecognized/unsupported datetimeunits so that there are just two strings to translate, not twoper datatype. Along the way, follow our usual error message styleof not double-quoting type names, and instead making sure that wesay the name is a type. Fix a couple of places in date.c thatwere using the wrong one of "unrecognized" and "unsupported".Nikhil Benesch, with a bit more editing by meDiscussion:https://postgr.es/m/CAPWqQZTURGixmbMH2_Z3ZtWGA0ANjUb9bwtkkxSxSfDeFHuM6Q@mail.gmail.com
1 parentba2bc4a commit4b16049

File tree

6 files changed

+76
-91
lines changed

6 files changed

+76
-91
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include<time.h>
2323

2424
#include"access/xact.h"
25+
#include"catalog/pg_type.h"
2526
#include"common/hashfn.h"
2627
#include"libpq/pqformat.h"
2728
#include"miscadmin.h"
@@ -1124,8 +1125,8 @@ extract_date(PG_FUNCTION_ARGS)
11241125
default:
11251126
ereport(ERROR,
11261127
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1127-
errmsg("date units\"%s\" not supported",
1128-
lowunits)));
1128+
errmsg("unit\"%s\" not supported for type %s",
1129+
lowunits,format_type_be(DATEOID))));
11291130
}
11301131
}
11311132
elseif (type==UNITS)
@@ -1207,8 +1208,8 @@ extract_date(PG_FUNCTION_ARGS)
12071208
default:
12081209
ereport(ERROR,
12091210
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1210-
errmsg("date units\"%s\" not supported",
1211-
lowunits)));
1211+
errmsg("unit\"%s\" not supported for type %s",
1212+
lowunits,format_type_be(DATEOID))));
12121213
intresult=0;
12131214
}
12141215
}
@@ -1223,16 +1224,17 @@ extract_date(PG_FUNCTION_ARGS)
12231224
default:
12241225
ereport(ERROR,
12251226
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1226-
errmsg("date units\"%s\" not supported",
1227-
lowunits)));
1227+
errmsg("unit\"%s\" not supported for type %s",
1228+
lowunits,format_type_be(DATEOID))));
12281229
intresult=0;
12291230
}
12301231
}
12311232
else
12321233
{
12331234
ereport(ERROR,
12341235
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1235-
errmsg("date units \"%s\" not recognized",lowunits)));
1236+
errmsg("unit \"%s\" not recognized for type %s",
1237+
lowunits,format_type_be(DATEOID))));
12361238
intresult=0;
12371239
}
12381240

@@ -2202,9 +2204,9 @@ time_part_common(PG_FUNCTION_ARGS, bool retnumeric)
22022204
caseDTK_ISOYEAR:
22032205
default:
22042206
ereport(ERROR,
2205-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2206-
errmsg("\"time\" units\"%s\" notrecognized",
2207-
lowunits)));
2207+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2208+
errmsg("unit\"%s\" notsupported for type %s",
2209+
lowunits,format_type_be(TIMEOID))));
22082210
intresult=0;
22092211
}
22102212
}
@@ -2219,8 +2221,8 @@ time_part_common(PG_FUNCTION_ARGS, bool retnumeric)
22192221
{
22202222
ereport(ERROR,
22212223
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2222-
errmsg("\"time\" units\"%s\" not recognized",
2223-
lowunits)));
2224+
errmsg("unit\"%s\" not recognized for type %s",
2225+
lowunits,format_type_be(TIMEOID))));
22242226
intresult=0;
22252227
}
22262228

@@ -2980,9 +2982,9 @@ timetz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
29802982
caseDTK_MILLENNIUM:
29812983
default:
29822984
ereport(ERROR,
2983-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2984-
errmsg("\"time with time zone\" units \"%s\" notrecognized",
2985-
lowunits)));
2985+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2986+
errmsg("unit \"%s\" notsupported for type %s",
2987+
lowunits,format_type_be(TIMETZOID))));
29862988
intresult=0;
29872989
}
29882990
}
@@ -3001,8 +3003,8 @@ timetz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
30013003
{
30023004
ereport(ERROR,
30033005
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3004-
errmsg("\"time with time zone\" units \"%s\" not recognized",
3005-
lowunits)));
3006+
errmsg("unit \"%s\" not recognized for type %s",
3007+
lowunits,format_type_be(TIMETZOID))));
30063008
intresult=0;
30073009
}
30083010

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

Lines changed: 41 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3972,8 +3972,8 @@ timestamp_trunc(PG_FUNCTION_ARGS)
39723972
default:
39733973
ereport(ERROR,
39743974
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3975-
errmsg("timestamp units\"%s\" not supported",
3976-
lowunits)));
3975+
errmsg("unit\"%s\" not supported for type %s",
3976+
lowunits,format_type_be(TIMESTAMPOID))));
39773977
result=0;
39783978
}
39793979

@@ -3986,8 +3986,8 @@ timestamp_trunc(PG_FUNCTION_ARGS)
39863986
{
39873987
ereport(ERROR,
39883988
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3989-
errmsg("timestamp units\"%s\" not recognized",
3990-
lowunits)));
3989+
errmsg("unit\"%s\" not recognized for type %s",
3990+
lowunits,format_type_be(TIMESTAMPOID))));
39913991
result=0;
39923992
}
39933993

@@ -4165,8 +4165,8 @@ timestamptz_trunc_internal(text *units, TimestampTz timestamp, pg_tz *tzp)
41654165
default:
41664166
ereport(ERROR,
41674167
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4168-
errmsg("timestamp with time zone units\"%s\" not"
4169-
"supported",lowunits)));
4168+
errmsg("unit\"%s\" notsupported for type %s",
4169+
lowunits,format_type_be(TIMESTAMPTZOID))));
41704170
result=0;
41714171
}
41724172

@@ -4182,8 +4182,8 @@ timestamptz_trunc_internal(text *units, TimestampTz timestamp, pg_tz *tzp)
41824182
{
41834183
ereport(ERROR,
41844184
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4185-
errmsg("timestamp with time zone units\"%s\" not recognized",
4186-
lowunits)));
4185+
errmsg("unit\"%s\" not recognized for type %s",
4186+
lowunits,format_type_be(TIMESTAMPTZOID))));
41874187
result=0;
41884188
}
41894189

@@ -4337,17 +4337,11 @@ interval_trunc(PG_FUNCTION_ARGS)
43374337
break;
43384338

43394339
default:
4340-
if (val==DTK_WEEK)
4341-
ereport(ERROR,
4342-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4343-
errmsg("interval units \"%s\" not supported "
4344-
"because months usually have fractional weeks",
4345-
lowunits)));
4346-
else
4347-
ereport(ERROR,
4348-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4349-
errmsg("interval units \"%s\" not supported",
4350-
lowunits)));
4340+
ereport(ERROR,
4341+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4342+
errmsg("unit \"%s\" not supported for type %s",
4343+
lowunits,format_type_be(INTERVALOID)),
4344+
(val==DTK_WEEK) ?errdetail("Months usually have fractional weeks.") :0));
43514345
}
43524346

43534347
if (tm2interval(tm,fsec,result)!=0)
@@ -4362,8 +4356,8 @@ interval_trunc(PG_FUNCTION_ARGS)
43624356
{
43634357
ereport(ERROR,
43644358
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4365-
errmsg("interval units\"%s\" not recognized",
4366-
lowunits)));
4359+
errmsg("unit\"%s\" not recognized for type %s",
4360+
lowunits,format_type_be(INTERVALOID))));
43674361
}
43684362

43694363
PG_RETURN_INTERVAL_P(result);
@@ -4559,18 +4553,11 @@ NonFiniteTimestampTzPart(int type, int unit, char *lowunits,
45594553
boolisNegative,boolisTz)
45604554
{
45614555
if ((type!=UNITS)&& (type!=RESERV))
4562-
{
4563-
if (isTz)
4564-
ereport(ERROR,
4565-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4566-
errmsg("timestamp with time zone units \"%s\" not recognized",
4567-
lowunits)));
4568-
else
4569-
ereport(ERROR,
4570-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4571-
errmsg("timestamp units \"%s\" not recognized",
4572-
lowunits)));
4573-
}
4556+
ereport(ERROR,
4557+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4558+
errmsg("unit \"%s\" not recognized for type %s",
4559+
lowunits,
4560+
format_type_be(isTz ?TIMESTAMPTZOID :TIMESTAMPOID))));
45744561

45754562
switch (unit)
45764563
{
@@ -4606,16 +4593,11 @@ NonFiniteTimestampTzPart(int type, int unit, char *lowunits,
46064593
returnget_float8_infinity();
46074594

46084595
default:
4609-
if (isTz)
4610-
ereport(ERROR,
4611-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4612-
errmsg("timestamp with time zone units \"%s\" not supported",
4613-
lowunits)));
4614-
else
4615-
ereport(ERROR,
4616-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4617-
errmsg("timestamp units \"%s\" not supported",
4618-
lowunits)));
4596+
ereport(ERROR,
4597+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4598+
errmsg("unit \"%s\" not supported for type %s",
4599+
lowunits,
4600+
format_type_be(isTz ?TIMESTAMPTZOID :TIMESTAMPOID))));
46194601
return0.0;/* keep compiler quiet */
46204602
}
46214603
}
@@ -4814,8 +4796,8 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
48144796
default:
48154797
ereport(ERROR,
48164798
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4817-
errmsg("timestamp units\"%s\" not supported",
4818-
lowunits)));
4799+
errmsg("unit\"%s\" not supported for type %s",
4800+
lowunits,format_type_be(TIMESTAMPOID))));
48194801
intresult=0;
48204802
}
48214803
}
@@ -4861,8 +4843,8 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
48614843
default:
48624844
ereport(ERROR,
48634845
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4864-
errmsg("timestamp units\"%s\" not supported",
4865-
lowunits)));
4846+
errmsg("unit\"%s\" not supported for type %s",
4847+
lowunits,format_type_be(TIMESTAMPOID))));
48664848
intresult=0;
48674849
}
48684850

@@ -4871,7 +4853,8 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
48714853
{
48724854
ereport(ERROR,
48734855
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4874-
errmsg("timestamp units \"%s\" not recognized",lowunits)));
4856+
errmsg("unit \"%s\" not recognized for type %s",
4857+
lowunits,format_type_be(TIMESTAMPOID))));
48754858
intresult=0;
48764859
}
48774860

@@ -5085,8 +5068,8 @@ timestamptz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
50855068
default:
50865069
ereport(ERROR,
50875070
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5088-
errmsg("timestamp with time zone units\"%s\" not supported",
5089-
lowunits)));
5071+
errmsg("unit\"%s\" not supported for type %s",
5072+
lowunits,format_type_be(TIMESTAMPTZOID))));
50905073
intresult=0;
50915074
}
50925075

@@ -5133,17 +5116,17 @@ timestamptz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
51335116
default:
51345117
ereport(ERROR,
51355118
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5136-
errmsg("timestamp with time zone units\"%s\" not supported",
5137-
lowunits)));
5119+
errmsg("unit\"%s\" not supported for type %s",
5120+
lowunits,format_type_be(TIMESTAMPTZOID))));
51385121
intresult=0;
51395122
}
51405123
}
51415124
else
51425125
{
51435126
ereport(ERROR,
51445127
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5145-
errmsg("timestamp with time zone units\"%s\" not recognized",
5146-
lowunits)));
5128+
errmsg("unit\"%s\" not recognized for type %s",
5129+
lowunits,format_type_be(TIMESTAMPTZOID))));
51475130

51485131
intresult=0;
51495132
}
@@ -5265,8 +5248,8 @@ interval_part_common(PG_FUNCTION_ARGS, bool retnumeric)
52655248
default:
52665249
ereport(ERROR,
52675250
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5268-
errmsg("interval units\"%s\" not supported",
5269-
lowunits)));
5251+
errmsg("unit\"%s\" not supported for type %s",
5252+
lowunits,format_type_be(INTERVALOID))));
52705253
intresult=0;
52715254
}
52725255
}
@@ -5326,8 +5309,8 @@ interval_part_common(PG_FUNCTION_ARGS, bool retnumeric)
53265309
{
53275310
ereport(ERROR,
53285311
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5329-
errmsg("interval units\"%s\" not recognized",
5330-
lowunits)));
5312+
errmsg("unit\"%s\" not recognized for type %s",
5313+
lowunits,format_type_be(INTERVALOID))));
53315314
intresult=0;
53325315
}
53335316

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,15 +1129,15 @@ SELECT EXTRACT(DECADE FROM DATE '0012-12-31 BC'); -- -2
11291129
-- all possible fields
11301130
--
11311131
SELECT EXTRACT(MICROSECONDS FROM DATE '2020-08-11');
1132-
ERROR:date units"microseconds" not supported
1132+
ERROR:unit"microseconds" not supported for type date
11331133
SELECT EXTRACT(MILLISECONDS FROM DATE '2020-08-11');
1134-
ERROR:date units"milliseconds" not supported
1134+
ERROR:unit"milliseconds" not supported for type date
11351135
SELECT EXTRACT(SECOND FROM DATE '2020-08-11');
1136-
ERROR:date units"second" not supported
1136+
ERROR:unit"second" not supported for type date
11371137
SELECT EXTRACT(MINUTE FROM DATE '2020-08-11');
1138-
ERROR:date units"minute" not supported
1138+
ERROR:unit"minute" not supported for type date
11391139
SELECT EXTRACT(HOUR FROM DATE '2020-08-11');
1140-
ERROR:date units"hour" not supported
1140+
ERROR:unit"hour" not supported for type date
11411141
SELECT EXTRACT(DAY FROM DATE '2020-08-11');
11421142
extract
11431143
---------
@@ -1235,11 +1235,11 @@ SELECT EXTRACT(DOY FROM DATE '2020-08-11');
12351235
(1 row)
12361236

12371237
SELECT EXTRACT(TIMEZONE FROM DATE '2020-08-11');
1238-
ERROR:date units"timezone" not supported
1238+
ERROR:unit"timezone" not supported for type date
12391239
SELECT EXTRACT(TIMEZONE_M FROM DATE '2020-08-11');
1240-
ERROR:date units"timezone_m" not supported
1240+
ERROR:unit"timezone_m" not supported for type date
12411241
SELECT EXTRACT(TIMEZONE_H FROM DATE '2020-08-11');
1242-
ERROR:date units"timezone_h" not supported
1242+
ERROR:unit"timezone_h" not supported for type date
12431243
SELECT EXTRACT(EPOCH FROM DATE '2020-08-11');
12441244
extract
12451245
------------
@@ -1462,7 +1462,7 @@ SELECT EXTRACT(EPOCH FROM DATE 'infinity'); -- Infinity
14621462
-- wrong fields from non-finite date:
14631463
--
14641464
SELECT EXTRACT(MICROSEC FROM DATE 'infinity'); -- error
1465-
ERROR:date units"microsec" not recognized
1465+
ERROR:unit"microsec" not recognized for type date
14661466
-- test constructors
14671467
select make_date(2013, 7, 15);
14681468
make_date

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,9 @@ SELECT f1,
963963
(10 rows)
964964

965965
SELECT EXTRACT(FORTNIGHT FROM INTERVAL '2 days'); -- error
966-
ERROR:interval units"fortnight" not recognized
966+
ERROR:unit"fortnight" not recognized for type interval
967967
SELECT EXTRACT(TIMEZONE FROM INTERVAL '2 days'); -- error
968-
ERROR:interval units"timezone" not supported
968+
ERROR:unit"timezone" not supported for type interval
969969
SELECT EXTRACT(DECADE FROM INTERVAL '100 y');
970970
extract
971971
---------

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ SELECT EXTRACT(HOUR FROM TIME '2020-05-26 13:30:25.575401');
161161
(1 row)
162162

163163
SELECT EXTRACT(DAY FROM TIME '2020-05-26 13:30:25.575401'); -- error
164-
ERROR:"time" units"day" notrecognized
164+
ERROR:unit"day" notsupported for type time without time zone
165165
SELECT EXTRACT(FORTNIGHT FROM TIME '2020-05-26 13:30:25.575401'); -- error
166-
ERROR:"time" units"fortnight" not recognized
166+
ERROR:unit"fortnight" not recognized for type time without time zone
167167
SELECT EXTRACT(TIMEZONE FROM TIME '2020-05-26 13:30:25.575401'); -- error
168-
ERROR:"time" units"timezone" notrecognized
168+
ERROR:unit"timezone" notsupported for type time without time zone
169169
SELECT EXTRACT(EPOCH FROM TIME '2020-05-26 13:30:25.575401');
170170
extract
171171
--------------

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ SELECT EXTRACT(HOUR FROM TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-
178178
(1 row)
179179

180180
SELECT EXTRACT(DAY FROM TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04'); -- error
181-
ERROR:"time with time zone" units "day" not recognized
181+
ERROR:unit "day" not supported for type time with time zone
182182
SELECT EXTRACT(FORTNIGHT FROM TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04'); -- error
183-
ERROR:"time with time zone" units "fortnight" not recognized
183+
ERROR:unit "fortnight" not recognized for type time with time zone
184184
SELECT EXTRACT(TIMEZONE FROM TIME WITH TIME ZONE '2020-05-26 13:30:25.575401-04:30');
185185
extract
186186
---------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp