Created
September 13, 2021 08:42
-
-
Save neos1803/79347e00cb09dcf8fa931dc658a5b62a to your computer and use it in GitHub Desktop.
Listen to change in one column on PostgreSQL
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 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$ |
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 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