Functions and Triggers
The Functions component copies your PostgreSQL functions and stored procedures. The Triggers component copies the triggers associated with your tables.
Functions
What Is Copied
- Function name and schema
- Parameters (names, types, default values)
- Return type
- Function body (the SQL/plpgsql code)
- Language (plpgsql, sql, plv8, etc.)
- Attributes (VOLATILE, STABLE, IMMUTABLE, SECURITY DEFINER, etc.)
Examples of Cloned Functions
- Business logic functions
- RPC functions called from the Supabase client
- Validation functions
- Stored procedures
Re-cloning
Functions use CREATE OR REPLACE — if the function already exists on the target, it is updated with the new definition. No duplicates.
Triggers
What Is Copied
- Trigger name
- Associated table
- Trigger event (INSERT, UPDATE, DELETE)
- Timing (BEFORE, AFTER, INSTEAD OF)
- Condition (WHEN clause)
- Function called by the trigger
Examples of Cloned Triggers
on_user_created— actions after a user signs upupdate_updated_at— automatically update theupdated_atfieldvalidate_data— validation before insertion
Clone Order
Triggers are cloned after functions, since a trigger references a function. The order is:
- Tables (structure)
- Functions
- Triggers
Key Considerations
| Situation | Behavior |
|---|---|
| Function already exists | Replaced (CREATE OR REPLACE) |
| Trigger already exists | Dropped and recreated |
| Function using an uninstalled extension | Fails — install the extension first |
| Trigger on an excluded table | The trigger is still cloned (the table exists, only the data is excluded) |
Next Steps
- RLS Policies — Clone access rules
- Tables and schema — Table structure