snapshot_table
Copy a table into a timestamped backup before destructive changes, enabling manual rollback and returning the snapshot name and row count.
Instructions
Runs CREATE TABLE tmp_[_]_backup_YYYYMMDD AS SELECT * FROM [WHERE ...]. Use it BEFORE a destructive operation so a manual rollback is possible afterwards. The name must fit in 63 bytes. Returns the snapshot table name and the number of rows copied.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| where | No | Optional condition, without the WHERE keyword (e.g. status = 'OPEN'). One condition only: no ";", no data-modifying statements and no setval. Without it the whole table is copied (dangerous on large tables) | |
| source | Yes | Source table (e.g. tab_invoice) | |
| suffix | No | Optional suffix for the name (e.g. "phase_a") -> tmp_source_phase_a_backup_YYYYMMDD |