mirror of
https://github.com/postgres/postgres.git
synced 2025-12-09 02:08:45 +03:00
Update some timestamp[tz] functions to use soft-error reporting
This commit updates two functions that convert "timestamptz" to "timestamp", and vice-versa, to use the soft error reporting rather than a their own logic to do the same. These are now named as follows: - timestamp2timestamptz_safe() - timestamptz2timestamp_safe() These functions were suffixed with "_opt_overflow", previously. This shaves some code, as it is possible to detect how a timestamp[tz] overflowed based on the returned value rather than a custom state. It is optionally possible for the callers of these functions to rely on the error generated internally by these functions, depending on the error context. Similar work has been done ind03668ea05and4246a977ba. Reviewed-by: Amul Sul <sulamul@gmail.com> Discussion: https://postgr.es/m/aS09YF2GmVXjAxbJ@paquier.xyz
This commit is contained in:
@@ -508,11 +508,11 @@ static Datum
|
||||
cvt_timestamptz_timestamp(Datum input)
|
||||
{
|
||||
TimestampTz val = DatumGetTimestampTz(input);
|
||||
ErrorSaveContext escontext = {T_ErrorSaveContext};
|
||||
Timestamp result;
|
||||
int overflow;
|
||||
|
||||
result = timestamptz2timestamp_opt_overflow(val, &overflow);
|
||||
/* We can ignore the overflow result, since result is useful as-is */
|
||||
result = timestamptz2timestamp_safe(val, (Node *) &escontext);
|
||||
/* We can ignore errors, since result is useful as-is */
|
||||
return TimestampGetDatum(result);
|
||||
}
|
||||
|
||||
@@ -543,11 +543,11 @@ static Datum
|
||||
cvt_timestamp_timestamptz(Datum input)
|
||||
{
|
||||
Timestamp val = DatumGetTimestamp(input);
|
||||
ErrorSaveContext escontext = {T_ErrorSaveContext};
|
||||
TimestampTz result;
|
||||
int overflow;
|
||||
|
||||
result = timestamp2timestamptz_opt_overflow(val, &overflow);
|
||||
/* We can ignore the overflow result, since result is useful as-is */
|
||||
result = timestamp2timestamptz_safe(val, (Node *) &escontext);
|
||||
/* We can ignore errors, since result is useful as-is */
|
||||
return TimestampTzGetDatum(result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user