pg_protect_columns
pg_protect_columns · A set of postgres functions that allow you to protect columns that should not be updated.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101081 | pg_protect_columns | pg_protect_columns | 0.0.2 | ADMIN | Unknown | SQL |
Usage
Sources:
pg_protect_columns prevents selected columns from changing during UPDATE by means of a row trigger. It is useful for application-level immutability rules, but it is not a substitute for privileges, row-level security, or constraints. The public package page currently exposes artifact version 0.0.1 even though catalog metadata reports 0.0.2.
Core Workflow
Install the package through database.dev/dbdev in an environment with the required trusted-language-extension support, then create a trigger on every protected table.
Changing a protected value raises restrict_violation. The underscore prefix helps this trigger run before later alphabetically named triggers, but trigger order must still be reviewed explicitly.
Controlled Bypass
disable_protection_on_column(text)sets a transaction-local bypass for one named column.re_enable_column_protection()clears that bypass. Call it as soon as the controlled update finishes, inside a tightly permissioned routine.- The bypass setting is not a general authorization system. Do not grant these helpers to roles that must remain unable to change protected values.
Caveats
- Trigger enforcement applies only where the trigger exists and is enabled. Owners, superusers, trigger-disabling operations, or replication paths may bypass it.
- Schema-qualify the functions if the package is installed outside the active search path.
- database.dev installation depends on pg_tle/dbdev support. Follow its backup guidance for trusted-language extensions, and test logical restore before relying on it for disaster recovery.