All rules

Style

postgresql/consistent-between-over-and

Enforce a consistent stance on `x BETWEEN a AND b` vs `x >= a AND x <= b`.

  • Type suggestion
  • Recommended off
  • Fixable yes

Why this matters

`BETWEEN` is the SQL-standard inclusive-range form and is shorter to read. The rule only flags inclusive comparisons (`>=` / `<=`) where both bounds reference the same expression — strict inequalities are not equivalent to `BETWEEN` and are out of scope. Flip with the `style` option for projects that prefer explicit comparisons.

Examples

Incorrect

Incorrect
SELECT * FROM t WHERE x >= 1 AND x <= 10;

Correct

Correct
SELECT * FROM t WHERE x BETWEEN 1 AND 10;
Correct
SELECT * FROM t WHERE x > 1 AND x < 10; -- strict bounds: out of scope

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-between-over-and": [
        "warn",
        {
          style: "always",
        },
      ],
    },
  },
];

Options

style "always" | "never" default: "always"
`always` (default) rewrites `>=` + `<=` pairs to `BETWEEN`. `never` rewrites `BETWEEN` back to explicit `>=` and `<=` comparisons.
Try this rule

Edit the SQL — only consistent-between-over-and 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 consistent-between-over-and — 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