mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
parent
c5de1225e9
commit
e5991f3ae5
4 changed files with 16 additions and 0 deletions
|
@ -37,6 +37,8 @@ pub enum DataType {
|
|||
Decimal(Option<u64>, Option<u64>),
|
||||
/// Floating point with optional precision e.g. FLOAT(8)
|
||||
Float(Option<u64>),
|
||||
/// Tiny integer
|
||||
TinyInt,
|
||||
/// Small integer
|
||||
SmallInt,
|
||||
/// Integer
|
||||
|
@ -91,6 +93,7 @@ impl fmt::Display for DataType {
|
|||
}
|
||||
}
|
||||
DataType::Float(size) => format_type_with_optional_length(f, "FLOAT", size),
|
||||
DataType::TinyInt => write!(f, "TINYINT"),
|
||||
DataType::SmallInt => write!(f, "SMALLINT"),
|
||||
DataType::Int => write!(f, "INT"),
|
||||
DataType::BigInt => write!(f, "BIGINT"),
|
||||
|
|
|
@ -444,6 +444,7 @@ define_keywords!(
|
|||
TIMESTAMP,
|
||||
TIMEZONE_HOUR,
|
||||
TIMEZONE_MINUTE,
|
||||
TINYINT,
|
||||
TO,
|
||||
TOP,
|
||||
TRAILING,
|
||||
|
|
|
@ -1938,6 +1938,7 @@ impl<'a> Parser<'a> {
|
|||
let _ = self.parse_keyword(Keyword::PRECISION);
|
||||
Ok(DataType::Double)
|
||||
}
|
||||
Keyword::TINYINT => Ok(DataType::TinyInt),
|
||||
Keyword::SMALLINT => Ok(DataType::SmallInt),
|
||||
Keyword::INT | Keyword::INTEGER => Ok(DataType::Int),
|
||||
Keyword::BIGINT => Ok(DataType::BigInt),
|
||||
|
|
|
@ -1017,6 +1017,17 @@ fn parse_cast() {
|
|||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
||||
let sql = "SELECT CAST(id AS TINYINT) FROM customer";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Cast {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("id"))),
|
||||
data_type: DataType::TinyInt
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
||||
one_statement_parses_to(
|
||||
"SELECT CAST(id AS BIGINT) FROM customer",
|
||||
"SELECT CAST(id AS BIGINT) FROM customer",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue