From b6e44b956550eedd427290aa38473a289a76617f Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Sat, 3 Jul 2021 11:19:53 +0800 Subject: [PATCH 1/2] Support tinyint --- src/ast/data_type.rs | 3 +++ src/dialect/keywords.rs | 1 + src/parser.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs index 388703e76..9e67f74cf 100644 --- a/src/ast/data_type.rs +++ b/src/ast/data_type.rs @@ -37,6 +37,8 @@ pub enum DataType { Decimal(Option, Option), /// Floating point with optional precision e.g. FLOAT(8) Float(Option), + /// 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"), diff --git a/src/dialect/keywords.rs b/src/dialect/keywords.rs index 8b88496b6..4ec988988 100644 --- a/src/dialect/keywords.rs +++ b/src/dialect/keywords.rs @@ -440,6 +440,7 @@ define_keywords!( TEXTFILE, THEN, TIES, + TINYINT, TIME, TIMESTAMP, TIMEZONE_HOUR, diff --git a/src/parser.rs b/src/parser.rs index 75d603a79..f7e90372e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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), From 0db7cfac980df4995ef4e55840ed240162c342b1 Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Mon, 5 Jul 2021 09:27:23 +0800 Subject: [PATCH 2/2] Add tests --- src/dialect/keywords.rs | 2 +- tests/sqlparser_common.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dialect/keywords.rs b/src/dialect/keywords.rs index 4ec988988..a0e7e323b 100644 --- a/src/dialect/keywords.rs +++ b/src/dialect/keywords.rs @@ -440,11 +440,11 @@ define_keywords!( TEXTFILE, THEN, TIES, - TINYINT, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE, + TINYINT, TO, TOP, TRAILING, diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index bbb9bdc26..18bc2a62e 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -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",