Skip to content

Instantly share code, notes, and snippets.

@neos1803
Created September 13, 2021 08:42
Show Gist options
  • Save neos1803/79347e00cb09dcf8fa931dc658a5b62a to your computer and use it in GitHub Desktop.
Save neos1803/79347e00cb09dcf8fa931dc658a5b62a to your computer and use it in GitHub Desktop.
Listen to change in one column on PostgreSQL
create or replace function test_notify()
returns trigger
language plpgsql
as $function$
begin
if ((new.status = '1' and old.status = '0') or (new.status = '0' and old.status = '1')) then
perform pg_notify('testEvent', row_to_json(new)::text);
end if;
return null;
end;
$function$
create trigger test_trigger after
update of status on table_test for each row execute procedure test_notify();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment