We have a database where every timestamp is defined as timestamp(3) with time zone
. We noticed that in some cases we were getting back timestamps with 6 fractional digits, not 3. I tracked this down to only happening in out update_date
columns, and only if it was updated via moddatetime
.
Does anybody have experience with gracefully fixing this?
I tested manual inserts, updates, from literal, from now(), etc and none of those cause the issue.
I'm aware of being able to fix this by casting to ::timestamptz(3)
wherever we use this field, but this will add a lot of mess, plus I am concerned about the performance if we need to do ... WHERE date_trunc('milliseconds', update_date) > other_tz3_value
.
The best I've come up with would be changing the index we have on update_date to a functional index on date_trunc('milliseconds', update_date)
, but again, this seems clunky.
The tables in question have a trigger like:
CREATE TRIGGER mytrigger
BEFORE UPDATE ON mytable
FOR EACH ROW EXECUTE PROCEDURE moddatetime(update_date);
My expectation would be that no matter how a value is inserted into a timestamp(3) field, it always comes back with no more than 3 fractional digits.