From 5efe2a028fa3b44b18da418e57d9b0739544740e Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Tue, 2 Jan 2024 09:53:15 +1100 Subject: [PATCH] Handle errors correctly --- src/parser/mod.rs | 4 ++-- tests/sqlparser_postgres.rs | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index b56068ae7d..995138a160 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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> = 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)?; } diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index da3f060837..f9e85e9c42 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -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]