beteran-api-kgon-server-ser.../migrations/202208041000_initialize/up.sql
2022-08-17 17:45:00 +00:00

17 lines
388 B
PL/PgSQL

CREATE OR REPLACE FUNCTION update_synchronizations()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO api_kgon_synchronizations
(item, last_code, synchronized_at)
VALUES
(NEW.item, NEW.code, (extract(epoch from now()) * 1000))
ON CONFLICT (item)
DO UPDATE
SET
last_code = NEW.code,
synchronized_at = (extract(epoch from now()) * 1000);
RETURN NEW;
END;
$$ language 'plpgsql';