mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-01 11:47:20 +00:00
Support NUMERIC without precision or scale
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#exact-numeric-type
This commit is contained in:
parent
54c9ca8619
commit
23a0d032bd
2 changed files with 11 additions and 7 deletions
|
@ -17,8 +17,8 @@ pub enum SQLType {
|
||||||
Varbinary(usize),
|
Varbinary(usize),
|
||||||
/// Large binary object e.g. BLOB(1000)
|
/// Large binary object e.g. BLOB(1000)
|
||||||
Blob(usize),
|
Blob(usize),
|
||||||
/// Decimal type with precision and optional scale e.g. DECIMAL(10,2)
|
/// Decimal type with optional precision and scale e.g. DECIMAL(10,2)
|
||||||
Decimal(usize, Option<usize>),
|
Decimal(Option<usize>, Option<usize>),
|
||||||
/// Small integer
|
/// Small integer
|
||||||
SmallInt,
|
SmallInt,
|
||||||
/// Integer
|
/// Integer
|
||||||
|
@ -75,9 +75,13 @@ impl ToString for SQLType {
|
||||||
SQLType::Blob(size) => format!("blob({})", size),
|
SQLType::Blob(size) => format!("blob({})", size),
|
||||||
SQLType::Decimal(precision, scale) => {
|
SQLType::Decimal(precision, scale) => {
|
||||||
if let Some(scale) = scale {
|
if let Some(scale) = scale {
|
||||||
format!("numeric({},{})", precision, scale)
|
format!("numeric({},{})", precision.unwrap(), scale)
|
||||||
} else {
|
} else {
|
||||||
format!("numeric({})", precision)
|
if let Some(precision) = precision {
|
||||||
|
format!("numeric({})", precision)
|
||||||
|
} else {
|
||||||
|
format!("numeric")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SQLType::SmallInt => "smallint".to_string(),
|
SQLType::SmallInt => "smallint".to_string(),
|
||||||
|
|
|
@ -1166,7 +1166,7 @@ impl Parser {
|
||||||
|
|
||||||
pub fn parse_optional_precision_scale(
|
pub fn parse_optional_precision_scale(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<(usize, Option<usize>), ParserError> {
|
) -> Result<(Option<usize>, Option<usize>), ParserError> {
|
||||||
if self.consume_token(&Token::LParen) {
|
if self.consume_token(&Token::LParen) {
|
||||||
let n = self.parse_literal_int()?;
|
let n = self.parse_literal_int()?;
|
||||||
let scale = if self.consume_token(&Token::Comma) {
|
let scale = if self.consume_token(&Token::Comma) {
|
||||||
|
@ -1175,9 +1175,9 @@ impl Parser {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
self.expect_token(&Token::RParen)?;
|
self.expect_token(&Token::RParen)?;
|
||||||
Ok((n as usize, scale))
|
Ok((Some(n as usize), scale))
|
||||||
} else {
|
} else {
|
||||||
parser_err!("Expecting `(`")
|
Ok((None, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue