Skip to content

Commit a6888fd

Browse files
committed
Refactor timestamp2timestamptz_opt_error()
While casting from timestamp to timestamptz we do timestamp2tm() then tm2timestamp(). This commit eliminates call to tm2timestamp(). Instead, it directly applies timezone offset to the original timestamp value. That makes upcoming datetime overflow handling in jsonpath easier. That should also save us some CPU cycles. Discussion: https://postgr.es/m/CAPpHfdvRPRh_mTGar5WmDeRZ%3DU5dOXHdxspYYD%3D76m3knNGjXA%40mail.gmail.com Author: Alexander Korotkov Reviewed-by: Tom Lane
1 parent db477b6 commit a6888fd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/backend/utils/adt/timestamp.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -5210,8 +5210,17 @@ timestamp2timestamptz_opt_error(Timestamp timestamp, bool *have_error)
52105210
{
52115211
tz = DetermineTimeZoneOffset(tm, session_timezone);
52125212

5213-
if (!tm2timestamp(tm, fsec, &tz, &result))
5213+
result = dt2local(timestamp, -tz);
5214+
5215+
if (IS_VALID_TIMESTAMP(result))
5216+
{
52145217
return result;
5218+
}
5219+
else if (have_error)
5220+
{
5221+
*have_error = true;
5222+
return (TimestampTz) 0;
5223+
}
52155224
}
52165225

52175226
if (have_error)

0 commit comments

Comments
 (0)