© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
John

Error in trigger function

tl;dr

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

I have this trigger function, where the error seems to happen in the first line. The
updated_at
updated_at
field stores a
timestamptz
timestamptz
value, which
NOW()
NOW()
should be, but doesn't seem to cooperate with me. I have tried both
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
and
NOW()
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
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
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Trigger Function
SupabaseSSupabase / help-and-questions
4y ago
Edge function <> Trigger
SupabaseSSupabase / help-and-questions
13mo ago
Trigger function help
SupabaseSSupabase / help-and-questions
3y ago
Unexpected error in database trigger
SupabaseSSupabase / help-and-questions
6mo ago