All rules
Performance
postgresql/
Warn on `LIKE`/`ILIKE` patterns that begin with `%`; they force sequential scans.
Why this matters
A pattern like `'%foo'` or `'%foo%'` cannot use a plain B-tree index and forces PostgreSQL into a sequential scan. Use a `pg_trgm` GIN index or full-text search if substring matching is required.
Examples
Incorrect
SELECT id FROM users WHERE email LIKE '%@example.com';SELECT id FROM users WHERE name ILIKE '%smith%';Correct
SELECT id FROM users WHERE email LIKE 'admin@%';SELECT id FROM users WHERE email = 'admin@example.com';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-leading-wildcard-like": "warn",
},
},
]; Options
Edit the SQL — only no-leading-wildcard-like 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-leading-wildcard-like — plus no-syntax-error as a safety net.