Skip to content

Commit a0873ca

Browse files
author
Agaev Huseyn
committed
Fix parsing of negative values
1 parent 4875dad commit a0873ca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/parser/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7274,6 +7274,16 @@ impl<'a> Parser<'a> {
72747274
let placeholder = tok.to_string() + &ident.value;
72757275
Ok(Value::Placeholder(placeholder))
72767276
}
7277+
tok @ Token::Minus => {
7278+
let next_token = self.next_token();
7279+
match next_token.token {
7280+
Token::Number(n, l) => Ok(Value::Number(
7281+
Self::parse::<String>(tok.to_string() + &n, location)?,
7282+
l,
7283+
)),
7284+
_ => self.expected("number", next_token),
7285+
}
7286+
}
72777287
unexpected => self.expected(
72787288
"a value",
72797289
TokenWithLocation {

tests/sqlparser_postgres.rs

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ fn parse_create_sequence() {
277277
"CREATE TEMPORARY SEQUENCE IF NOT EXISTS name3 INCREMENT 1 NO MINVALUE MAXVALUE 20 OWNED BY NONE",
278278
);
279279

280+
let sql7 = "CREATE SEQUENCE name4
281+
AS BIGINT
282+
INCREMENT -10
283+
MINVALUE - 2000 MAXVALUE -5
284+
START WITH - 20";
285+
pg().one_statement_parses_to(
286+
sql7,
287+
"CREATE SEQUENCE name4 AS BIGINT INCREMENT -10 MINVALUE -2000 MAXVALUE -5 START WITH -20",
288+
);
289+
280290
assert!(matches!(
281291
pg().parse_sql_statements("CREATE SEQUENCE foo INCREMENT 1 NO MINVALUE NO"),
282292
Err(ParserError::ParserError(_))

0 commit comments

Comments
 (0)