© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
7 replies
Smardrengr

Help with a trigger

Not a trigger expert... I would like to sum the
num
num
of confirmed
players
players
in the
games
games
table each time a player record is created, updated or deleted. Here’s my non-working code:

drop function if exists games_players cascade;

create or replace function games_players()
returns trigger as $$ begin
update games set players_conf = (select sum(players.num) AS num from players where players.game_id = NEW.game_id group by players.game_id) where games.id = NEW.game_id;
return NEW;
end;
$$ language plpgsql;
drop function if exists games_players cascade;

create or replace function games_players()
returns trigger as $$ begin
update games set players_conf = (select sum(players.num) AS num from players where players.game_id = NEW.game_id group by players.game_id) where games.id = NEW.game_id;
return NEW;
end;
$$ language plpgsql;


Any ideas?
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

Help with a trigger + function
SupabaseSSupabase / help-and-questions
4y ago
Trigger function help
SupabaseSSupabase / help-and-questions
3y ago
Prevent supabase client updateUser (need help with trigger)
SupabaseSSupabase / help-and-questions
13mo ago
How to edit a trigger
SupabaseSSupabase / help-and-questions
3y ago