古いバージョンが新しいバージョンを上書きしないようにするには、次の単純な関数を使用します。
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
定義は同じtimestamp without time zone
です。
paramts
値は関数によって提供されます。
create function myfetch(...)
language plpgsql AS
$$
begin
return query select ts, ... from record where ...;
end
$$;
ノード API と Angular クライアント UI が取得するのは2021-04-16T21:37:35.878Zで、値は に送信されmyupdate()
ます。ただし、西海岸のサーバーの 1 つで、 内での実行中にmyupdate()
、ts
PST 2021-04-16 14:37:35.878694に自動変換され、右側に 3 つの余分な数字があります。
UTC と同じ精度の両方を比較する方法は?