All rules

Safety

postgresql/no-volatile-default-on-add-column

Disallow `ADD COLUMN ... DEFAULT <volatile>()` (forces full table rewrite).

  • Type problem
  • Recommended error
  • Fixable no

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

Incorrect
ALTER TABLE t ADD COLUMN x integer DEFAULT random();
Incorrect
ALTER TABLE t ADD COLUMN id uuid DEFAULT gen_random_uuid();

Correct

Correct
ALTER TABLE t ADD COLUMN x integer DEFAULT 1;
Correct
ALTER TABLE t ADD COLUMN z timestamptz DEFAULT now();
Correct
ALTER TABLE t ADD COLUMN id integer; -- no default at all is fine

Configure 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

This rule has no options.

Try this rule

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.

0 errors 0 warnings parse 0ms · rules 0ms
Diagnostics

No issues found.

2 rules enabled.

Rule under test no-volatile-default-on-add-column — plus no-syntax-error as a safety net.
eslint-plugin-postgresql

An ESLint plugin that lints .sql files with real PostgreSQL grammar and a curated set of best-practice rules.

© 2026 eslint-plugin-postgresql contributors Built on libpg-query · PostgreSQL 17