Repository navigation
Conversation
…ut a dialect Signed-off-by: minleejae <mmj9808@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PostgreSQL's table-level
[CONSTRAINT name] NOT NULL columnand[CONSTRAINT name] {UNIQUE | PRIMARY KEY} USING INDEX indexconstraints were read only withDialect.POSTGRESQL. Without a dialect,ALTER TABLE t ADD CONSTRAINT nn NOT NULL idandALTER TABLE t ADD CONSTRAINT uk UNIQUE USING INDEX t_idxwere parse errors, while the other PostgreSQL constraint forms (NOT VALID,EXCLUDE,DEFERRABLE INITIALLY DEFERRED,VALIDATE CONSTRAINT) have parsed without a dialect since #2847. Callers that parse DDL from several databases without choosing a dialect had to special-case these two.This change reads both forms with
Dialect.POSTGRESQLand without a dialect, never with another dialect:ALTER TABLE ... ADD [CONSTRAINT name] NOT NULL column [NO INHERIT] [NOT VALID]and the same table constraint inCREATE TABLEproduce aNotNullConstraint.ALTER TABLE ... ADD [CONSTRAINT name] {UNIQUE | PRIMARY KEY} USING INDEX index [attributes]produces aConstraintUsingIndex.Both reuse the existing
PostgreSqlNotNullConstraintandPostgreSqlConstraintUsingIndexproductions, so the result is the same object model as withDialect.POSTGRESQL. The lookahead for the NOT NULL form lives in the existing nestedAlterConstraintLookaheadclass.Compatibility: only statements that were parse errors without a dialect are affected. Statements that already parsed keep their representation (
ADD CONSTRAINT pk PRIMARY KEY (id) USING INDEX pk,ADD UNIQUE USING BTREE (c),ADD c INT NOT NULL). MySQL, Oracle and the other dialects still reject both forms. The testpostgreSqlOnlyFormsStillRequireThePostgreSqlDialectadded in #2847 pinned the old behaviour and is replaced.Reference: PostgreSQL 18 ALTER TABLE (
ADD table_constraint [ NOT VALID ],ADD table_constraint_using_index), CREATE TABLE (table_constraint:NOT NULL column_name [ NO INHERIT ]).Validation
AlterAddTableConstraintTest: the two forms and their variants (unnamed,NO INHERIT,NOT VALID,PRIMARY KEY USING INDEX, several actions in one statement) parse without a dialect, round-trip, and give the same constraint classes as withDialect.POSTGRESQL;CREATE TABLEwith a table-levelNOT NULL; both forms are still rejected withDialect.MYSQLandDialect.ORACLE. These statements fail on the base (ed17b37f4).ADD CONSTRAINT n NOT NULL c,ADD NOT NULL c,... NO INHERIT,... NOT VALID,ADD CONSTRAINT n UNIQUE USING INDEX i,ADD PRIMARY KEY USING INDEX i,CREATE TABLE t (id int, CONSTRAINT n NOT NULL id NO INHERIT)).gradle check(Spotless, Checkstyle, PMD, JaCoCo verification): 16,654 tests, 0 failures, 25 skipped.AI assistance: prepared with Claude Code.