© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
14 replies
gduteaud

Trigger function help

Hi folks!

I'm trying to set up a trigger + function so that when a row is added to a certain table (call it "table 1"), if the new row respects some conditions, a new row is created into another table (table 2) and some of its column values are set from the new row in table 1.

THEN I'd like the function to create more rows in table 2, with each subsequent iteration having a certain column value incremented until it stops respecting a condition set based on the new row in table 1.

I've had a go at writing the function using an if statement followed by a for loop but it's not working (no new row is created in table 2 when a new row is created in table 1) and I can't figure out why. Is it possible to achieve what I'm describing within a single function, or do I need two (one for the initial new table 2 row, and then another to be called for each additional row that's required)?

Thanks!
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
Help with a trigger + function
SupabaseSSupabase / help-and-questions
4y ago
Edge function <> Trigger
SupabaseSSupabase / help-and-questions
13mo ago
Error in trigger function
SupabaseSSupabase / help-and-questions
4y ago