mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Switch some numeric-related functions to use soft error reporting
This commit changes some functions related to the data type numeric to
use the soft error reporting rather than a custom boolean flag (called
"have_error") that callers of these functions could rely on to bypass
the generation of ERROR reports, letting the callers do their own error
handling (timestamp, jsonpath and numeric_to_char() require them).
This results in the removal of some boilerplate code that was required
to handle both the ereport() and the "have_error" code paths bypassing
ereport(), unifying everything under the soft error reporting facility.
While on it, some duplicated error messages are removed. The function
upgraded in this commit were suffixed with "_opt_error" in their names.
They are renamed to "_safe" instead.
This change relies on d9f7f5d32f, that has introduced the soft error
reporting infrastructure.
Author: Amul Sul <sulamul@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/CAAJ_b96No5h5tRuR+KhcC44YcYUCw8WAHuLoqqyyop8_k3+JDQ@mail.gmail.com
This commit is contained in:
@@ -5629,11 +5629,11 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
|
||||
|
||||
case DTK_JULIAN:
|
||||
if (retnumeric)
|
||||
PG_RETURN_NUMERIC(numeric_add_opt_error(int64_to_numeric(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)),
|
||||
numeric_div_opt_error(int64_to_numeric(((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * INT64CONST(1000000) + fsec),
|
||||
int64_to_numeric(SECS_PER_DAY * INT64CONST(1000000)),
|
||||
NULL),
|
||||
NULL));
|
||||
PG_RETURN_NUMERIC(numeric_add_safe(int64_to_numeric(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)),
|
||||
numeric_div_safe(int64_to_numeric(((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * INT64CONST(1000000) + fsec),
|
||||
int64_to_numeric(SECS_PER_DAY * INT64CONST(1000000)),
|
||||
NULL),
|
||||
NULL));
|
||||
else
|
||||
PG_RETURN_FLOAT8(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) +
|
||||
((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
@@ -5685,11 +5685,11 @@ timestamp_part_common(PG_FUNCTION_ARGS, bool retnumeric)
|
||||
result = int64_div_fast_to_numeric(timestamp - epoch, 6);
|
||||
else
|
||||
{
|
||||
result = numeric_div_opt_error(numeric_sub_opt_error(int64_to_numeric(timestamp),
|
||||
int64_to_numeric(epoch),
|
||||
NULL),
|
||||
int64_to_numeric(1000000),
|
||||
NULL);
|
||||
result = numeric_div_safe(numeric_sub_safe(int64_to_numeric(timestamp),
|
||||
int64_to_numeric(epoch),
|
||||
NULL),
|
||||
int64_to_numeric(1000000),
|
||||
NULL);
|
||||
result = DatumGetNumeric(DirectFunctionCall2(numeric_round,
|
||||
NumericGetDatum(result),
|
||||
Int32GetDatum(6)));
|
||||
@@ -5903,11 +5903,11 @@ timestamptz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
|
||||
|
||||
case DTK_JULIAN:
|
||||
if (retnumeric)
|
||||
PG_RETURN_NUMERIC(numeric_add_opt_error(int64_to_numeric(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)),
|
||||
numeric_div_opt_error(int64_to_numeric(((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * INT64CONST(1000000) + fsec),
|
||||
int64_to_numeric(SECS_PER_DAY * INT64CONST(1000000)),
|
||||
NULL),
|
||||
NULL));
|
||||
PG_RETURN_NUMERIC(numeric_add_safe(int64_to_numeric(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday)),
|
||||
numeric_div_safe(int64_to_numeric(((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * INT64CONST(1000000) + fsec),
|
||||
int64_to_numeric(SECS_PER_DAY * INT64CONST(1000000)),
|
||||
NULL),
|
||||
NULL));
|
||||
else
|
||||
PG_RETURN_FLOAT8(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) +
|
||||
((((tm->tm_hour * MINS_PER_HOUR) + tm->tm_min) * SECS_PER_MINUTE) +
|
||||
@@ -5956,11 +5956,11 @@ timestamptz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
|
||||
result = int64_div_fast_to_numeric(timestamp - epoch, 6);
|
||||
else
|
||||
{
|
||||
result = numeric_div_opt_error(numeric_sub_opt_error(int64_to_numeric(timestamp),
|
||||
int64_to_numeric(epoch),
|
||||
NULL),
|
||||
int64_to_numeric(1000000),
|
||||
NULL);
|
||||
result = numeric_div_safe(numeric_sub_safe(int64_to_numeric(timestamp),
|
||||
int64_to_numeric(epoch),
|
||||
NULL),
|
||||
int64_to_numeric(1000000),
|
||||
NULL);
|
||||
result = DatumGetNumeric(DirectFunctionCall2(numeric_round,
|
||||
NumericGetDatum(result),
|
||||
Int32GetDatum(6)));
|
||||
@@ -6247,9 +6247,9 @@ interval_part_common(PG_FUNCTION_ARGS, bool retnumeric)
|
||||
result = int64_div_fast_to_numeric(val, 6);
|
||||
else
|
||||
result =
|
||||
numeric_add_opt_error(int64_div_fast_to_numeric(interval->time, 6),
|
||||
int64_to_numeric(secs_from_day_month),
|
||||
NULL);
|
||||
numeric_add_safe(int64_div_fast_to_numeric(interval->time, 6),
|
||||
int64_to_numeric(secs_from_day_month),
|
||||
NULL);
|
||||
|
||||
PG_RETURN_NUMERIC(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user