Skip to content

fix: read PostgreSQL NO INHERIT and named column NOT NULL constraints without a dialect - #2966

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/no-inherit-default-20261201
Dec 2, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/no-inherit-default-20261201

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

PostgreSQL's NO INHERIT constraint clause was read only with Dialect.POSTGRESQL. Without a dialect, CREATE TABLE t (id INT CHECK (id > 0) NO INHERIT), CREATE TABLE t (id INT NOT NULL NO INHERIT), ALTER TABLE t ADD CONSTRAINT ck CHECK (id > 0) NO INHERIT and ALTER TABLE t ADD COLUMN c INT NOT NULL NO INHERIT were parse errors, while the table-level NOT NULL column NO INHERIT constraint has parsed without a dialect since #2942. A named column NOT NULL (id INT CONSTRAINT nn NOT NULL) parsed without a dialect, but as three unrelated column options.

This change reads these forms with Dialect.POSTGRESQL and without a dialect, never with another dialect, through the productions the dialect already uses:

  • CHECK (...) NO INHERIT in a column constraint, a table constraint and ALTER TABLE ... ADD [CONSTRAINT name] CHECK sets CheckConstraint.isNoInherit(). A table constraint also takes NO INHERIT after [NOT] ENFORCED, and is printed in the dialect's order (NO INHERIT NOT ENFORCED). A column constraint does not, as in PostgreSQL.
  • [CONSTRAINT name] NOT NULL [NO INHERIT] on a column produces a NotNullConstraint, as with Dialect.POSTGRESQL.

The dialect check reuses isPostgreSqlTableConstraintDialect().

Compatibility: without a dialect, CONSTRAINT nn NOT NULL on a column is now one ColumnOption of kind CONSTRAINT that holds a NotNullConstraint named nn, instead of the options CONSTRAINT, nn and NOT NULL. toString() is unchanged. Other statements that already parsed keep their representation. MySQL, Oracle and the other dialects are unchanged: they still reject NO INHERIT and keep their reading of CONSTRAINT nn NOT NULL. As with Dialect.POSTGRESQL, a repeated NO INHERIT in a table constraint is still rejected, although PostgreSQL accepts it.

Reference: PostgreSQL 18 CREATE TABLE (column_constraint: NOT NULL [ NO INHERIT ], CHECK ( expression ) [ NO INHERIT ]; table_constraint), ALTER TABLE (ADD table_constraint, ADD COLUMN).

Validation

  • PostgreSqlCheckNoInheritTest, PostgreSqlColumnNotNullTest: the forms parse without a dialect, round-trip, and give the same model as with Dialect.POSTGRESQL, in CREATE TABLE and ALTER TABLE; NOT ENFORCED NO INHERIT of a table constraint is printed in the dialect's order; the column constraint in that order and a repeated column NO INHERIT are rejected with and without the dialect; MySQL and Oracle still reject NO INHERIT and keep their reading of CONSTRAINT nn NOT NULL. 14 of these cases fail on the base (2ba80d35c).
  • PostgreSQL 18.3 agreed with the branch on all 23 statements I checked (the test forms plus rejected ones: UNIQUE NO INHERIT, repeated column NO INHERIT, the column constraint with NOT ENFORCED NO INHERIT), except the repeated table-level NO INHERIT noted above.
  • Java 17 gradle check (Spotless, Checkstyle, PMD, JaCoCo verification): 16,858 tests, 0 failures, 25 skipped.

AI assistance: prepared with Claude Code.

… without a dialect

Signed-off-by: minleejae <mmj9808@gmail.com>
@manticore-projects
manticore-projects merged commit da7cf75 into JSQLParser:master Dec 2, 2026
10 checks passed
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