#include <time.h>
#include "access/xact.h"
+#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("date units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(DATEOID))));
}
}
else if (type == UNITS)
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("date units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(DATEOID))));
intresult = 0;
}
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("date units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(DATEOID))));
intresult = 0;
}
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("date units \"%s\" not recognized", lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(DATEOID))));
intresult = 0;
}
case DTK_ISOYEAR:
default:
ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time\" units \"%s\" not recognized",
- lowunits)));
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMEOID))));
intresult = 0;
}
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time\" units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMEOID))));
intresult = 0;
}
case DTK_MILLENNIUM:
default:
ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time with time zone\" units \"%s\" not recognized",
- lowunits)));
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMETZOID))));
intresult = 0;
}
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("\"time with time zone\" units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMETZOID))));
intresult = 0;
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPOID))));
result = 0;
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMESTAMPOID))));
result = 0;
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp with time zone units \"%s\" not "
- "supported", lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPTZOID))));
result = 0;
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp with time zone units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMESTAMPTZOID))));
result = 0;
}
break;
default:
- if (val == DTK_WEEK)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("interval units \"%s\" not supported "
- "because months usually have fractional weeks",
- lowunits)));
- else
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("interval units \"%s\" not supported",
- lowunits)));
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(INTERVALOID)),
+ (val == DTK_WEEK) ? errdetail("Months usually have fractional weeks.") : 0));
}
if (tm2interval(tm, fsec, result) != 0)
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("interval units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(INTERVALOID))));
}
PG_RETURN_INTERVAL_P(result);
bool isNegative, bool isTz)
{
if ((type != UNITS) && (type != RESERV))
- {
- if (isTz)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp with time zone units \"%s\" not recognized",
- lowunits)));
- else
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp units \"%s\" not recognized",
- lowunits)));
- }
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits,
+ format_type_be(isTz ? TIMESTAMPTZOID : TIMESTAMPOID))));
switch (unit)
{
return get_float8_infinity();
default:
- if (isTz)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp with time zone units \"%s\" not supported",
- lowunits)));
- else
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp units \"%s\" not supported",
- lowunits)));
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits,
+ format_type_be(isTz ? TIMESTAMPTZOID : TIMESTAMPOID))));
return 0.0; /* keep compiler quiet */
}
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPOID))));
intresult = 0;
}
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPOID))));
intresult = 0;
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp units \"%s\" not recognized", lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMESTAMPOID))));
intresult = 0;
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp with time zone units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPTZOID))));
intresult = 0;
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("timestamp with time zone units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(TIMESTAMPTZOID))));
intresult = 0;
}
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("timestamp with time zone units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(TIMESTAMPTZOID))));
intresult = 0;
}
default:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("interval units \"%s\" not supported",
- lowunits)));
+ errmsg("unit \"%s\" not supported for type %s",
+ lowunits, format_type_be(INTERVALOID))));
intresult = 0;
}
}
{
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("interval units \"%s\" not recognized",
- lowunits)));
+ errmsg("unit \"%s\" not recognized for type %s",
+ lowunits, format_type_be(INTERVALOID))));
intresult = 0;
}
-- all possible fields
--
SELECT EXTRACT(MICROSECONDS FROM DATE '2020-08-11');
-ERROR: date units "microseconds" not supported
+ERROR: unit "microseconds" not supported for type date
SELECT EXTRACT(MILLISECONDS FROM DATE '2020-08-11');
-ERROR: date units "milliseconds" not supported
+ERROR: unit "milliseconds" not supported for type date
SELECT EXTRACT(SECOND FROM DATE '2020-08-11');
-ERROR: date units "second" not supported
+ERROR: unit "second" not supported for type date
SELECT EXTRACT(MINUTE FROM DATE '2020-08-11');
-ERROR: date units "minute" not supported
+ERROR: unit "minute" not supported for type date
SELECT EXTRACT(HOUR FROM DATE '2020-08-11');
-ERROR: date units "hour" not supported
+ERROR: unit "hour" not supported for type date
SELECT EXTRACT(DAY FROM DATE '2020-08-11');
extract
---------
(1 row)
SELECT EXTRACT(TIMEZONE FROM DATE '2020-08-11');
-ERROR: date units "timezone" not supported
+ERROR: unit "timezone" not supported for type date
SELECT EXTRACT(TIMEZONE_M FROM DATE '2020-08-11');
-ERROR: date units "timezone_m" not supported
+ERROR: unit "timezone_m" not supported for type date
SELECT EXTRACT(TIMEZONE_H FROM DATE '2020-08-11');
-ERROR: date units "timezone_h" not supported
+ERROR: unit "timezone_h" not supported for type date
SELECT EXTRACT(EPOCH FROM DATE '2020-08-11');
extract
------------
-- wrong fields from non-finite date:
--
SELECT EXTRACT(MICROSEC FROM DATE 'infinity'); -- error
-ERROR: date units "microsec" not recognized
+ERROR: unit "microsec" not recognized for type date
-- test constructors
select make_date(2013, 7, 15);
make_date