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!
Was this page helpful?