SupabaseS
Supabase4y ago
John

Error in trigger function

tl;dr

NEW.updated_at := NOW(); is not working, where updated_at stores a timestamptz value.

I have this trigger function, where the error seems to happen in the first line. The updated_at field stores a timestamptz value, which NOW() should be, but doesn't seem to cooperate with me. I have tried both CURRENT_TIMESTAMP and NOW() and neither seems to work. Does anyone know what might be causing this issue?

BEGIN
  NEW.updated_at := NOW();
  UPDATE public.projects 
  SET updated_at = NEW.updated_at 
  WHERE id = NEW.project_id;
  INSERT INTO public.document_contributor (document_id, contributor)
  VALUES (NEW.id, NEW.created_by)
  ON CONFLICT
  DO NOTHING;
  INSERT INTO public.commits (message, created_by, project_id, document_id, created_at, previous_content, current_content)
  VALUES (NEW.note, NEW.updated_by, NEW.project_id, NEW.id, NEW.updated_at, OLD.content, NEW.content);
  RETURN NEW;
END
unknown.png
Was this page helpful?