Skip to content

Commit 23a0d03

Browse files
committed
1 parent 54c9ca8 commit 23a0d03

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/sqlast/sqltype.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub enum SQLType {
1717
Varbinary(usize),
1818
/// Large binary object e.g. BLOB(1000)
1919
Blob(usize),
20-
/// Decimal type with precision and optional scale e.g. DECIMAL(10,2)
21-
Decimal(usize, Option<usize>),
20+
/// Decimal type with optional precision and scale e.g. DECIMAL(10,2)
21+
Decimal(Option<usize>, Option<usize>),
2222
/// Small integer
2323
SmallInt,
2424
/// Integer
@@ -75,9 +75,13 @@ impl ToString for SQLType {
7575
SQLType::Blob(size) => format!("blob({})", size),
7676
SQLType::Decimal(precision, scale) => {
7777
if let Some(scale) = scale {
78-
format!("numeric({},{})", precision, scale)
78+
format!("numeric({},{})", precision.unwrap(), scale)
7979
} else {
80-
format!("numeric({})", precision)
80+
if let Some(precision) = precision {
81+
format!("numeric({})", precision)
82+
} else {
83+
format!("numeric")
84+
}
8185
}
8286
}
8387
SQLType::SmallInt => "smallint".to_string(),

src/sqlparser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ impl Parser {
11661166

11671167
pub fn parse_optional_precision_scale(
11681168
&mut self,
1169-
) -> Result<(usize, Option<usize>), ParserError> {
1169+
) -> Result<(Option<usize>, Option<usize>), ParserError> {
11701170
if self.consume_token(&Token::LParen) {
11711171
let n = self.parse_literal_int()?;
11721172
let scale = if self.consume_token(&Token::Comma) {
@@ -1175,9 +1175,9 @@ impl Parser {
11751175
None
11761176
};
11771177
self.expect_token(&Token::RParen)?;
1178-
Ok((n as usize, scale))
1178+
Ok((Some(n as usize), scale))
11791179
} else {
1180-
parser_err!("Expecting `(`")
1180+
Ok((None, None))
11811181
}
11821182
}
11831183

0 commit comments

Comments
 (0)