Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’3y agoβ€’
8 replies
sharki

Failed to create database function: failed to create pg.functions: syntax error at or near "create"

Hey devs, am getting this error when trying to make a function that stores new users from the auth.user table to public.user table.
--Insert a row into public.user
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
  insert into public.user (id, name, email)
  values (new.id, new.name, new.email);
  return new;
end;
$$;

-- trigger the function every time a user is created
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
--Insert a row into public.user
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
  insert into public.user (id, name, email)
  values (new.id, new.name, new.email);
  return new;
end;
$$;

-- trigger the function every time a user is created
create trigger on_auth_user_created
  after insert on auth.users
  for each row execute procedure public.handle_new_user();
Screenshot_2023-12-15_135541.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

Failed to create function failed to create pg.functions- syntax error at or near if
SupabaseSSupabase / help-and-questions
4y ago
Failed to create pg.functions syntax error...
SupabaseSSupabase / help-and-questions
4y ago
RLS Policy syntax error at or near "create"
SupabaseSSupabase / help-and-questions
3y ago
syntax error at or near boolean
SupabaseSSupabase / help-and-questions
4y ago