Skip to content

Conversation

AlexVulaj
Copy link

Summary

Adds support for PostgreSQL DO statements to the SQL linter. Previously, the linter would fail with "sql-lint was unable to lint the following query" errors when encountering DO anonymous code blocks, which are commonly used in PostgreSQL migration files.

Background

The linter was throwing parsing errors on valid PostgreSQL migration files containing DO statements like:

  DO $$
  BEGIN
      IF NOT EXISTS (
          SELECT 1 FROM information_schema.table_constraints
          WHERE constraint_name = 'fk_example_constraint'
          AND table_name = 'example_table'
      ) THEN
          ALTER TABLE example_table ADD CONSTRAINT fk_example_constraint
          FOREIGN KEY (example_id) REFERENCES other_table(id);
      END IF;
  END $$;

Changes

  • Added DO keyword to src/syntax/keywords.ts
  • Created PostgreSQL DO statement handler at src/lexer/statements/postgres/do.ts following the same pattern as existing statement handlers
  • Updated statement factory in src/lexer/statementFactory.ts to recognize and handle do statements
  • Added barrel export in src/barrel/statements.ts

The implementation follows the existing codebase patterns and conventions used by other PostgreSQL statement handlers like ALTER, CREATE, etc.

Test Plan

  • Built project successfully with npm run build
  • Tested with migration files containing DO statements - no more "unable to lint" errors
  • Verified the linter now recognizes DO as valid SQL syntax

Impact

This resolves parsing failures for PostgreSQL migration files that use DO statements, allowing the SQL linter to process these files without errors.

Adds parsing support for PostgreSQL DO anonymous code blocks to prevent
"unable to lint" errors when processing migration files containing DO statements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant