I have a table with event entity
create table event_entity
(
id varchar(36) not null
constraint constraint_4
primary key,
details_json varchar(2550),
event_time bigint,
type varchar(255),
user_id varchar(255)
);
details_json
has such data:
{
"custom_required_action":"VERIFY_EMAIL",
}
I need to create a trigger and notify on inserted row event_entity
table with condition:
WHERE type = 'CUSTOM_REQUIRED_ACTION' AND details_json:custom_required_action = 'VERIFY_EMAIL'
I've made it with
CREATE OR REPLACE FUNCTION notify_verifyEmail()
RETURNS trigger AS $$
DECLARE
BEGIN
PERFORM pg_notify(
'verifyEmail',
row_to_json(NEW)::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER notify_verifyEmail
AFTER INSERT ON event_entity
FOR EACH ROW
WHEN (new.type = 'CUSTOM_REQUIRED_ACTION')
EXECUTE PROCEDURE notify_verifyEmail();
But how to add second condition with details_json
field?