This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$ | |
DECLARE | |
id bigint; | |
BEGIN | |
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN | |
id = NEW.id; | |
ELSE | |
id = OLD.id; | |
END IF; | |
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text); |