Skip to content

Commit

Permalink
Handle errors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyhede committed Jan 1, 2024
1 parent c672b47 commit 5efe2a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4874,13 +4874,13 @@ impl<'a> Parser<'a> {
None
};

let _ = self.expect_keywords(&[Keyword::AS, Keyword::IDENTITY]);
let _ = self.expect_keywords(&[Keyword::AS, Keyword::IDENTITY])?;

let mut sequence_options: Option<Vec<SequenceOptions>> = None;

if self.peek_token().token == Token::LParen {
self.expect_token(&Token::LParen)?;
sequence_options = self.parse_create_sequence_options().ok();
sequence_options = Some(self.parse_create_sequence_options()?);
self.expect_token(&Token::RParen)?;
}

Expand Down
24 changes: 23 additions & 1 deletion tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,30 @@ fn parse_alter_table_alter_column_add_generated() {
pg_and_generic().verified_stmt(
"ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( INCREMENT 1 MINVALUE 1 )",
);

pg_and_generic().verified_stmt("ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( )");

let res = pg().parse_sql_statements(
"ALTER TABLE t ALTER COLUMN id ADD GENERATED ( INCREMENT 1 MINVALUE 1 )",
);
assert_eq!(
ParserError::ParserError("Expected AS, found: (".to_string()),
res.unwrap_err()
);

let res = pg().parse_sql_statements(
"ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( INCREMENT )",
);
assert_eq!(
ParserError::ParserError("Expected a value, found: )".to_string()),
res.unwrap_err()
);

let res =
pg().parse_sql_statements("ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY (");
assert_eq!(
ParserError::ParserError("Expected ), found: EOF".to_string()),
res.unwrap_err()
);
}

#[test]
Expand Down

0 comments on commit 5efe2a0

Please sign in to comment.