Skip to content

Commit

Permalink
Fix parsing of negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
Agaev Huseyn committed Sep 10, 2024
1 parent 4875dad commit a0873ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7274,6 +7274,16 @@ impl<'a> Parser<'a> {
let placeholder = tok.to_string() + &ident.value;
Ok(Value::Placeholder(placeholder))
}
tok @ Token::Minus => {
let next_token = self.next_token();
match next_token.token {
Token::Number(n, l) => Ok(Value::Number(
Self::parse::<String>(tok.to_string() + &n, location)?,
l,
)),
_ => self.expected("number", next_token),
}
}
unexpected => self.expected(
"a value",
TokenWithLocation {
Expand Down
10 changes: 10 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ fn parse_create_sequence() {
"CREATE TEMPORARY SEQUENCE IF NOT EXISTS name3 INCREMENT 1 NO MINVALUE MAXVALUE 20 OWNED BY NONE",
);

let sql7 = "CREATE SEQUENCE name4
AS BIGINT
INCREMENT -10
MINVALUE - 2000 MAXVALUE -5
START WITH - 20";
pg().one_statement_parses_to(
sql7,
"CREATE SEQUENCE name4 AS BIGINT INCREMENT -10 MINVALUE -2000 MAXVALUE -5 START WITH -20",
);

assert!(matches!(
pg().parse_sql_statements("CREATE SEQUENCE foo INCREMENT 1 NO MINVALUE NO"),
Err(ParserError::ParserError(_))
Expand Down

0 comments on commit a0873ca

Please sign in to comment.