I have a timestamp column in a PostgreSQL (13.3) table in Supabase. It currently stores timestamps to microsecond resolution. I want to send the timestamps to a javascript client and use them to query back (via Supabase) for exactly matching rows by this timestamp value. Javascript Date objects drop the microseconds and only store the milliseconds. I could store the microseconds string along with the Date object (that I need for presentation in various UI components) in the javascript client but this seems unnecessarily messy and error prone as the duplicated data could get out of sync.
Is it possible to force the timestamp values created in PostgreSQL to always be to millisecond and not microsecond resolution? Currently I am using the following for the CREATE TABLE and inside the upsert function:
CREATE TABLE abc (
-- other fields
modified_at timestamp without time zone DEFAULT now()::timestamp(3) NOT NULL
);
UPDATE abc
SET
-- other fields
modified_at = now()::timestamp(3)
WHERE modified_at = item.modified_at;
Related to this question.