All rules

Style

postgresql/align-column-definitions

Align column definitions vertically inside `CREATE TABLE`.

  • Type layout
  • Recommended off
  • Fixable yes

Why this matters

Aligns the name, type, and constraint columns of every `ColumnDef` row inside a `CREATE TABLE`. Multi-line column definitions and shared-line layouts are skipped because source surgery is unsafe in those shapes.

Examples

Incorrect

Incorrect
CREATE TABLE t (
  a TEXT NOT NULL,
  b non_blank_text_64[] NOT NULL,
  c INTEGER NOT NULL
);

Correct

Correct
CREATE TABLE t (
  a  TEXT                  NOT NULL,
  b  non_blank_text_64[]   NOT NULL,
  c  INTEGER               NOT NULL
);

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/align-column-definitions": [
        "warn",
        {
          gap: 2,
        },
      ],
    },
  },
];

Options

gap integer (>= 1) default: 2
Number of spaces to leave between aligned columns.
Try this rule

Edit the SQL — only align-column-definitions 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 align-column-definitions — 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