diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index dec2fad..460c620 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -2281,8 +2281,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf, /* timezone not specified? then use session timezone */ if (tzp != NULL && !(fmask & DTK_M(TZ))) { - struct pg_tm tt, - *tmp = &tt; + static struct pg_tm tt; + struct pg_tm *tmp = &tt; /* * daylight savings time modifier but no standard timezone? then error @@ -2291,7 +2291,17 @@ DecodeTimeOnly(char **field, int *ftype, int nf, return DTERR_BAD_FORMAT; if ((fmask & DTK_DATE_M) == 0) - GetCurrentDateTime(tmp); + { + static TimestampTz cached_txts; + TimestampTz cur_txts = GetCurrentTransactionStartTimestamp(); + + // Only fetch the struct pg_tm if the tx timestamp is changed + if (cached_txts != cur_txts) + { + cached_txts = cur_txts; + GetCurrentDateTime(tmp); + } + } else { /* a date has to be specified */