- Data validation: Enforce complex validation rules beyond what constraints can provide
- Audit logging: Automatically track changes to sensitive data
- Derived data: Maintain summary tables or denormalized data in sync
- Error handling: Capture and route problematic data to separate tables for analysis
- Notifications: Send alerts or update external systems when data changes
Create a trigger
This example creates a new table callederror_conditions with the same schema as conditions, but that only stores
records which are considered errors. An error, in this case, is when an application sends a temperature or
humidity reading with a value that is greater than or equal to 1000.
1
Create a function that inserts erroneous data into the error_conditions table
2
Create a trigger that calls this function whenever a new row is inserted into the hypertable
3
Verify the trigger works
All data is inserted into the
conditions table, but rows that contain errors are also added to the
error_conditions table.BEFORE INSERT, AFTER INSERT, BEFORE UPDATE,
AFTER UPDATE, BEFORE DELETE, and AFTER DELETE. For more information, see the docs.