Skip to content

Commit 346d1ff

Browse files
committed
Improve error messages in parse_create()
By not swallowing the Err from parse_data_type(). Also switch to `match` to enable parsing table-level constraints in this loop later.
1 parent a0f625b commit 346d1ff

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/sqlparser.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ impl Parser {
552552
let mut columns = vec![];
553553
if self.consume_token(&Token::LParen) {
554554
loop {
555-
if let Some(Token::SQLWord(column_name)) = self.next_token() {
556-
if let Ok(data_type) = self.parse_data_type() {
555+
match self.next_token() {
556+
Some(Token::SQLWord(column_name)) => {
557+
let data_type = self.parse_data_type()?;
557558
let is_primary = self.parse_keywords(vec!["PRIMARY", "KEY"]);
558559
let is_unique = self.parse_keyword("UNIQUE");
559560
let default = if self.parse_keyword("DEFAULT") {
@@ -586,18 +587,17 @@ impl Parser {
586587
}
587588
other => {
588589
return parser_err!(
589-
format!("Expected ',' or ')' after column definition but found {:?}", other)
590-
);
590+
format!("Expected ',' or ')' after column definition but found {:?}", other)
591+
);
591592
}
592593
}
593-
} else {
594+
}
595+
unexpected => {
594596
return parser_err!(format!(
595-
"Error parsing data type in column definition near: {:?}",
596-
self.peek_token()
597+
"Expected column name, got {:?}",
598+
unexpected
597599
));
598600
}
599-
} else {
600-
return parser_err!("Error parsing column name");
601601
}
602602
}
603603
}

0 commit comments

Comments
 (0)