Get Mystery Box with random crypto!

/* PostgreSQL Work with trigger */ :::1. Create new function | SergeyGurin

/*
PostgreSQL
Work with trigger
*/

:::1. Create new function
--drop function sync_record;
create function sync_record() returns trigger
language plpgsql
as
$$
BEGIN
NEW.updated_at = current_timestamp;
// ....
insert into sync_hcard (hcard_id, sync_event_type) values (NEW.id, 1);
RETURN NEW;
END
$$;

:::2. Create new trigger
--drop trigger check_update on hcard_data;
create trigger check_update
before insert or update
on hcard_data
for each row
execute procedure sync_record();

:::3. Check
SELECT event_object_table
,trigger_name
,event_manipulation
,action_statement
,action_timing
FROM information_schema.triggers
WHERE event_object_table = 'hcard_data' -- Your table name comes here
ORDER BY event_object_table
,event_manipulation;