How can I automatically delete row after set time by trigger?

30 Views Asked by At

I am trying to automatic deletion data system in supabase, but it doesn't work.

The default value of 'deleted_at' in 'comments' table is null, if a value not null is inputted, the trigger works a function.

The function deletes data 10 seconds after input, and the code is as follows.

BEGIN
  IF NEW.deleted_at IS NOT NULL THEN
    NEW.delete_time := NOW() + INTERVAL '10 seconds';
    PERFORM pg_notify('delete_comment_row_schedule', NEW.comment_id::text);
  END IF;

  RETURN NEW;
END;

Trigger events is set to after update.

Please help me!!

0

There are 0 best solutions below