Skip to content

Conversation

@mvzink
Copy link
Contributor

@mvzink mvzink commented Jan 23, 2026

MySQL allows CONSTRAINT CHECK (expr) without a name - the database will auto-generate a constraint name. This is a MySQL extension; the SQL standard requires a name after the CONSTRAINT keyword. See docs.

Previously, we required an identifier after CONSTRAINT, causing us to interpret CONSTRAINT as a column name in cases like:

CREATE TABLE t (x INT, CONSTRAINT CHECK (x > 1))

Now we check if the token after CONSTRAINT is a constraint type keyword (CHECK, PRIMARY, UNIQUE, FOREIGN) and treat the name as optional for dialects that support this. This is just MySQL as far as I know (and Generic), but we introduce a new Dialect flag even though it's a minor feature. We could remove the flag and allow the more permissive optional name syntax across dialects if desired.

MySQL allows `CONSTRAINT CHECK (expr)` without a name - the database will
auto-generate a constraint name. This is a MySQL extension; the SQL standard
requires a name after the CONSTRAINT keyword. See [docs].

Previously, we required an identifier after CONSTRAINT, causing us to
interpret CONSTRAINT as a column name in cases like:

```sql
CREATE TABLE t (x INT, CONSTRAINT CHECK (x > 1))
```

Now we check if the token after CONSTRAINT is a constraint type keyword
(CHECK, PRIMARY, UNIQUE, FOREIGN) and treat the name as optional for
dialects that support this. This is just MySQL as far as I know (and
Generic), but we introduce a new `Dialect` flag even though it's a minor
feature. We could remove the flag and allow the more permissive optional
name syntax across dialects if desired.

[docs]: https://dev.mysql.com/doc/refman/8.4/en/create-table.html
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