All rules
Safety
postgresql/
Disallow `ADD COLUMN ... DEFAULT <volatile>()` (forces full table rewrite).
Why this matters
PG10+ has a stable-default short-cut: `ADD COLUMN ... DEFAULT <constant or STABLE>` does not rewrite the table. A `VOLATILE` default forces a full table rewrite under `ACCESS EXCLUSIVE`. The rule curates the volatile-function list — `random`, `gen_random_uuid`, `uuid_generate_v1*`, `uuid_generate_v4`, `clock_timestamp`, `timeofday`. STABLE defaults like `now()` / `current_timestamp` are not flagged. One layer of `TypeCast` is unwrapped so `gen_random_uuid()::uuid` is detected.
Examples
Incorrect
ALTER TABLE t ADD COLUMN x integer DEFAULT random();ALTER TABLE t ADD COLUMN id uuid DEFAULT gen_random_uuid();Correct
ALTER TABLE t ADD COLUMN x integer DEFAULT 1;ALTER TABLE t ADD COLUMN z timestamptz DEFAULT now();ALTER TABLE t ADD COLUMN id integer; -- no default at all is fineConfigure it
// eslint.config.js
import postgresql from "eslint-plugin-postgresql";
export default [
{
files: ["**/*.sql"],
languageOptions: {
parser: postgresql.configs.recommended.languageOptions.parser,
},
plugins: { postgresql },
rules: {
"postgresql/no-volatile-default-on-add-column": "error",
},
},
]; Options
Edit the SQL — only no-volatile-default-on-add-column is enabled.
Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.
Diagnostics
No issues found.
2 rules enabled.
Rule under test
no-volatile-default-on-add-column — plus no-syntax-error as a safety net.