© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•6mo ago•
4 replies
fredguest

Unexpected error in database trigger

Following the basic example of creating a profile when a new user is created in the
auth.users
auth.users
table, it works fine when simply inserting a new record into the
public.profiles
public.profiles
table as follows:
begin
  insert into public.profiles (id, email, invite_id)
  values (new.id, new.email, (new.raw_user_meta_data ->> 'invite_id')::uuid);
  return new;
end;
begin
  insert into public.profiles (id, email, invite_id)
  values (new.id, new.email, (new.raw_user_meta_data ->> 'invite_id')::uuid);
  return new;
end;


However, if I use the same
invite_id
invite_id
from
raw_user_meta_data
raw_user_meta_data
to update the
public.invites
public.invites
table as follows, I get an error:
begin
  update public.invites set receiver_id = new.id
  where id = (new.raw_user_meta_data ->> 'invite_id')::uuid;

  insert into public.profiles (id, email)
  values (new.id, new.email);
  return new;
end;
begin
  update public.invites set receiver_id = new.id
  where id = (new.raw_user_meta_data ->> 'invite_id')::uuid;

  insert into public.profiles (id, email)
  values (new.id, new.email);
  return new;
end;


The error has a code of "unexpected_failure" and a message of "Database error saving new user". The schema is correct and the RLS policy allows updates to the
public.invites
public.invites
table, not sure what else it could be. Hard to debug these triggers.
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

Database trigger
SupabaseSSupabase / help-and-questions
5mo ago
Database Trigger
SupabaseSSupabase / help-and-questions
3y ago
triggers in database
SupabaseSSupabase / help-and-questions
3y ago
Error in trigger function
SupabaseSSupabase / help-and-questions
4y ago