IndexSeek commented on code in PR #1990: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1990#discussion_r2249946963
########## src/parser/mod.rs: ########## @@ -11229,6 +11229,38 @@ impl<'a> Parser<'a> { } } + /// Parse a scale value for NUMERIC/DECIMAL data types. + /// + /// Supports positive, negative, and explicitly positive (with `+`) scale values. + /// Negative scale values are particularly useful for PostgreSQL, where they indicate + /// rounding to the left of the decimal point. For example: + /// - `NUMERIC(5, 2)` stores up to 5 digits with 2 decimal places (e.g., 123.45) + /// - `NUMERIC(5, -2)` stores up to 5 digits rounded to hundreds (e.g., 12300) + fn parse_scale_value(&mut self) -> Result<i64, ParserError> { + let next_token = self.next_token(); + match next_token.token { + Token::Number(s, _) => Self::parse::<i64>(s, next_token.span.start), + Token::Minus => { + let next_token = self.next_token(); + match next_token.token { + Token::Number(s, _) => { + let positive_value = Self::parse::<i64>(s, next_token.span.start)?; + Ok(-positive_value) + } + _ => self.expected("number after minus", next_token), + } + } + Token::Plus => { + let next_token = self.next_token(); + match next_token.token { + Token::Number(s, _) => Self::parse::<i64>(s, next_token.span.start), + _ => self.expected("number after plus", next_token), + } + } + _ => self.expected("number", next_token), + } Review Comment: Wow, yes, this is much simpler and a way better way to handle the signs. Thank you! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org