All rules
Safety
postgresql/
Enforce a consistent stance on `CREATE OR REPLACE` for `FUNCTION` / `PROCEDURE` / `VIEW`.
Why this matters
Two valid stances exist: (a) always use `CREATE OR REPLACE` so re-running a migration is idempotent, or (b) never use it so unintended overwrites are surfaced as `relation already exists`. Pick one with the `style` option; the rule auto-fixes either way. `CREATE TABLE` / `CREATE INDEX` are out of scope (they don't support `OR REPLACE`).
Examples
Incorrect
CREATE FUNCTION fn() RETURNS void LANGUAGE SQL AS '';CREATE PROCEDURE p() LANGUAGE SQL AS '';CREATE VIEW v AS SELECT 1;Correct
CREATE OR REPLACE FUNCTION fn() RETURNS void LANGUAGE SQL AS '';CREATE OR REPLACE PROCEDURE p() LANGUAGE SQL AS '';CREATE OR REPLACE VIEW v AS SELECT 1;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/consistent-create-or-replace": [
"warn",
{
style: "always",
},
],
},
},
]; Options
Edit the SQL — only consistent-create-or-replace 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
consistent-create-or-replace — plus no-syntax-error as a safety net.