© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
rchrdnsh

Syntax Error on query, but don't know what to fix...

I am trying to create two tables for users and place them in one or the other table based on part of their email address.

-- inserts a row into either providers or team tables based on email address
create function public.handle_and_place_new_user()

returns trigger as $$

begin
  
  if position('@arrowgtp.com' in new.email) > 0 then
    insert into public.team (id, full_name, avatar_url, role)
    values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url', 'team');
  else
    insert into public.providers (id, full_name, avatar_url)
    values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
  end if;
  
  return new;
end;

$$ language plpgsql security definer;

-- 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_and_place_new_user()
-- inserts a row into either providers or team tables based on email address
create function public.handle_and_place_new_user()

returns trigger as $$

begin
  
  if position('@arrowgtp.com' in new.email) > 0 then
    insert into public.team (id, full_name, avatar_url, role)
    values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url', 'team');
  else
    insert into public.providers (id, full_name, avatar_url)
    values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
  end if;
  
  return new;
end;

$$ language plpgsql security definer;

-- 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_and_place_new_user()

...and I get the syntax error:

Failed to validate sql query: syntax error at or near "insert"
Failed to validate sql query: syntax error at or near "insert"

...but I am new to sql and don't really know what I'm doing, so it's hard for me to figure out what is wrong...

Any advice would be very appreciated, thank you 🙂
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

Don't see any records but able to query it
SupabaseSSupabase / help-and-questions
3y ago
Session auto refresh, but I don't know what's causing it
SupabaseSSupabase / help-and-questions
13mo ago
Don't know what to do with access token and etc
SupabaseSSupabase / help-and-questions
4y ago
Function syntax error
SupabaseSSupabase / help-and-questions
4y ago