Skip to content

fix(parser): model ALTER COLUMN nullability actions - #2529

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/alter-column-nullability-ast
Sep 3, 2026
Merged

fix(parser): model ALTER COLUMN nullability actions#2529
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/alter-column-nullability-ast

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

What

  • Add a dedicated AlterExpression.ColumnSetNotNull AST model for ALTER COLUMN ... SET NOT NULL.
  • Match the existing ColumnDropNotNull production before the generic column-data-type production.
  • Preserve both actions through AlterExpression.toString().
  • Validate the affected column name in AlterValidator.
  • Add AST, parse/deparse, validation, and reflection coverage.

Why

Both statements currently parse, but their ASTs are not reliable:

ALTER TABLE test_table ALTER COLUMN name SET NOT NULL;
ALTER TABLE test_table ALTER COLUMN name DROP NOT NULL;

SET NOT NULL is represented as a column data type named SET with [NOT, NULL] in its raw column specs. DROP NOT NULL is also consumed by the generic column-data-type branch even though a dedicated ColumnDropNotNull model already exists. Consumers therefore have to inspect and reconstruct raw tokens instead of using the AST.

This change gives both PostgreSQL nullability actions explicit AST representations without changing unrelated column option parsing.

PostgreSQL grammar reference: https://www.postgresql.org/docs/current/sql-altertable.html

Testing

  • ./gradlew check
  • Added parse/deparse and AST assertions for both actions.
  • Added validator coverage for SET NOT NULL.
  • Added the new model to ReflectionModelTest.

AI assistance

OpenAI Codex was used to trace the grammar branch selection, prepare the AST/deparser/validator changes, and run validation. The generated change and tests were reviewed against the PostgreSQL documentation.

Represent SET NOT NULL with a dedicated AST node and match DROP NOT NULL before the generic column-data-type branch. Cover parsing, deparsing, validation, and reflection.
@minleejae
minleejae force-pushed the fix/alter-column-nullability-ast branch from 6c66159 to 466f1bd Compare September 3, 2026 06:26
@manticore-projects
manticore-projects merged commit 8397d3a into JSQLParser:master Sep 3, 2026
7 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thanks!

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.

2 participants