Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlite): Fix UNIQUE parsing #4293

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sqlglot/dialects/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ class Parser(parser.Parser):
}
STRING_ALIASES = True

def _parse_unique(self) -> exp.UniqueColumnConstraint:
# Do not consume more tokens if UNIQUE is used as a standalone constraint, e.g:
# CREATE TABLE foo (bar TEXT UNIQUE REFERENCES baz ...)
if self._curr.text.upper() in self.CONSTRAINT_PARSERS:
return self.expression(exp.UniqueColumnConstraint)

return super()._parse_unique()

class Generator(generator.Generator):
JOIN_HINTS = False
TABLE_HINTS = False
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@ def test_ddl(self):
"mysql": "CREATE TABLE `x` (`Name` VARCHAR(200) NOT NULL)",
},
)

self.validate_identity(
"CREATE TABLE store (store_id INTEGER PRIMARY KEY AUTOINCREMENT, mgr_id INTEGER NOT NULL UNIQUE REFERENCES staff ON UPDATE CASCADE)"
)
Loading