]> granicus.if.org Git - postgresql/commitdiff
Refactor timestamp2timestamptz_opt_error()
authorAlexander Korotkov <akorotkov@postgresql.org>
Mon, 21 Oct 2019 20:03:55 +0000 (23:03 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Mon, 21 Oct 2019 20:07:07 +0000 (23:07 +0300)
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
src/backend/utils/adt/timestamp.c

index 84bc97d40c37600ba32f5972ab1d564a8ea1a75a..90ebb50e1f5eb9ac5a765d08f023ff75b0023616 100644 (file)
@@ -5210,8 +5210,17 @@ timestamp2timestamptz_opt_error(Timestamp timestamp, bool *have_error)
        {
                tz = DetermineTimeZoneOffset(tm, session_timezone);
 
-               if (!tm2timestamp(tm, fsec, &tz, &result))
+               result = dt2local(timestamp, -tz);
+
+               if (IS_VALID_TIMESTAMP(result))
+               {
                        return result;
+               }
+               else if (have_error)
+               {
+                       *have_error = true;
+                       return (TimestampTz) 0;
+               }
        }
 
        if (have_error)