Notes/sql/0002.sql

18 lines
399 B
MySQL
Raw Normal View History

2023-06-18 20:13:35 +02:00
ALTER TABLE node ADD COLUMN updated TIMESTAMP NOT NULL DEFAULT NOW();
CREATE OR REPLACE FUNCTION node_update_timestamp()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS $$
BEGIN
IF NEW.updated = OLD.updated THEN
UPDATE node SET updated = NOW() WHERE id=NEW.id;
END IF;
RETURN NEW;
END;
$$;
CREATE OR REPLACE TRIGGER node_update AFTER UPDATE ON node
FOR EACH ROW
EXECUTE PROCEDURE node_update_timestamp()