diff --git a/src/sqlast/sqltype.rs b/src/sqlast/sqltype.rs index eeb7ffe5..06a09203 100644 --- a/src/sqlast/sqltype.rs +++ b/src/sqlast/sqltype.rs @@ -17,8 +17,8 @@ pub enum SQLType { Varbinary(usize), /// Large binary object e.g. BLOB(1000) Blob(usize), - /// Decimal type with precision and optional scale e.g. DECIMAL(10,2) - Decimal(usize, Option), + /// Decimal type with optional precision and scale e.g. DECIMAL(10,2) + Decimal(Option, Option), /// Small integer SmallInt, /// Integer @@ -75,9 +75,13 @@ impl ToString for SQLType { SQLType::Blob(size) => format!("blob({})", size), SQLType::Decimal(precision, scale) => { if let Some(scale) = scale { - format!("numeric({},{})", precision, scale) + format!("numeric({},{})", precision.unwrap(), scale) } else { - format!("numeric({})", precision) + if let Some(precision) = precision { + format!("numeric({})", precision) + } else { + format!("numeric") + } } } SQLType::SmallInt => "smallint".to_string(), diff --git a/src/sqlparser.rs b/src/sqlparser.rs index ed0fd82b..f2b9cc31 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -1166,7 +1166,7 @@ impl Parser { pub fn parse_optional_precision_scale( &mut self, - ) -> Result<(usize, Option), ParserError> { + ) -> Result<(Option, Option), ParserError> { if self.consume_token(&Token::LParen) { let n = self.parse_literal_int()?; let scale = if self.consume_token(&Token::Comma) { @@ -1175,9 +1175,9 @@ impl Parser { None }; self.expect_token(&Token::RParen)?; - Ok((n as usize, scale)) + Ok((Some(n as usize), scale)) } else { - parser_err!("Expecting `(`") + Ok((None, None)) } }