Why this matters
PostgreSQL accepts both forms; this rule picks one and rewrites the other. Default is the operator form `x::int`. Switch with the `form` option.
Examples
Incorrect
SELECT CAST(x AS integer) FROM t;SELECT CAST(x AS varchar(255)) FROM t;Correct
SELECT x::integer FROM t;SELECT x::numeric(10, 2) FROM t;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/prefer-cast-operator": [
"warn",
{
form: "operator",
},
],
},
},
]; Options
Edit the SQL — only prefer-cast-operator 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
prefer-cast-operator — plus no-syntax-error as a safety net.