To prevent older version overwrite new version, in this simple function:
create function myupdate(paramts timestamp without time zone, ...)
language plpgsql AS
$$
begin
-- step 1 compare current record timestamp vs. supplied timestamp
if exists (select 1 from record where ts <> paramts and ...) then
raise exception 'A newer version exists, cannot update.';
end if;
...
end
$$;
ts
definition is the same timestamp without time zone
.
paramts
value is supplied by a function:
create function myfetch(...)
language plpgsql AS
$$
begin
return query select ts, ... from record where ...;
end
$$;
What node API and Angular client UI gets is 2021-04-16T21:37:35.878Z so is the value submitted to myupdate()
. However, at one of our West Coast server, during execution inside of myupdate()
, ts
is auto-converted to PST 2021-04-16 14:37:35.878694 and has 3 extra digits at right.
How to compare both in UTC and same precision?