Commit 28fef8b
committed
Add support for unnamed CONSTRAINT CHECK syntax
Fixes parsing of `CONSTRAINT CHECK (expr)` without a constraint name,
which is valid in MySQL and nom-sql.
Previously, the parser would consume the CHECK keyword as the constraint
name, then fail when it encountered the opening parenthesis.
The fix checks if the next token after CONSTRAINT is a constraint keyword
(PRIMARY, UNIQUE, FOREIGN, or CHECK). If so, it treats the constraint as
unnamed rather than trying to parse the keyword as an identifier.
Examples that now parse correctly:
- CREATE TABLE t (x INT, CONSTRAINT CHECK (x > 1))
- ALTER TABLE t ADD CONSTRAINT PRIMARY KEY (id)
- ALTER TABLE t ADD CONSTRAINT UNIQUE (email)
These canonicalize to their forms without the CONSTRAINT keyword when
no name is provided.1 parent 982f766 commit 28fef8b
2 files changed
+36
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8825 | 8825 | | |
8826 | 8826 | | |
8827 | 8827 | | |
8828 | | - | |
| 8828 | + | |
| 8829 | + | |
| 8830 | + | |
| 8831 | + | |
| 8832 | + | |
| 8833 | + | |
| 8834 | + | |
| 8835 | + | |
| 8836 | + | |
8829 | 8837 | | |
8830 | 8838 | | |
8831 | 8839 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5088 | 5088 | | |
5089 | 5089 | | |
5090 | 5090 | | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
| 5113 | + | |
| 5114 | + | |
| 5115 | + | |
| 5116 | + | |
| 5117 | + | |
5091 | 5118 | | |
5092 | 5119 | | |
5093 | 5120 | | |
| |||
0 commit comments