All rules

Style

postgresql/consistent-as-for-column-alias

Enforce a consistent stance on the `AS` keyword before column aliases in `SELECT`.

  • Type layout
  • Recommended off
  • Fixable yes

Why this matters

PostgreSQL allows `SELECT id user_id`, but the optional `AS` is the SQL-standard form and is far easier to read at a glance — without `AS`, an accidental missing comma silently turns a column into an alias of the previous one. Use the `style` option to enforce either direction.

Examples

Incorrect

Incorrect
SELECT id user_id, name full_name FROM users;

Correct

Correct
SELECT id AS user_id, name AS full_name FROM users;

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-as-for-column-alias": [
        "warn",
        {
          style: "always",
        },
      ],
    },
  },
];

Options

style "always" | "never" default: "always"
`always` (default) requires `AS` before column aliases. `never` forbids the keyword.
Try this rule

Edit the SQL — only consistent-as-for-column-alias 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-as-for-column-alias — 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