The following statement suffers a race condition which I can reliably demonstrate by executing it concurrent in very quick succession. Is there a way to remove this race condition from the below of do I need to take a different approach altogether?
INSERT INTO scheduled_event_log ("key") SELECT 'test' WHERE NOT EXISTS( SELECT AGE(now() at time zone 'utc', timestamp_utc) FROM scheduled_event_log WHERE "key" = 'test' AND age(now() at time zone 'utc', timestamp_utc) < '6s' FOR UPDATE);
Table as follows:
CREATE TABLE scheduled_event_log ( "key" varchar(64) NOT NULL, "timestamp_utc" timestamp without time zone default (now() at time zone 'utc') );