feat: Add support for parsing the syntax of MySQL UNIQUE KEY. (#962)

Co-authored-by: yukunpeng <yukunpeng@zhoupudata.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
artorias1024 2023-09-08 18:58:31 +08:00 committed by GitHub
parent bb7b05e106
commit 0480ee9886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 3 deletions

View file

@ -3941,9 +3941,15 @@ impl<'a> Parser<'a> {
match next_token.token {
Token::Word(w) if w.keyword == Keyword::PRIMARY || w.keyword == Keyword::UNIQUE => {
let is_primary = w.keyword == Keyword::PRIMARY;
if is_primary {
self.expect_keyword(Keyword::KEY)?;
}
// parse optional [KEY]
let _ = self.parse_keyword(Keyword::KEY);
// optional constraint name
let name = self
.maybe_parse(|parser| parser.parse_identifier())
.or(name);
let columns = self.parse_parenthesized_column_list(Mandatory, false)?;
Ok(Some(TableConstraint::Unique {
name,