mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-19 20:29:47 +00:00
parent
46b7c03788
commit
e951cd5278
5 changed files with 42 additions and 2 deletions
|
@ -53,6 +53,14 @@ pub enum DataType {
|
||||||
SmallInt(Option<u64>),
|
SmallInt(Option<u64>),
|
||||||
/// Unsigned small integer with optional display width e.g. SMALLINT UNSIGNED or SMALLINT(5) UNSIGNED
|
/// Unsigned small integer with optional display width e.g. SMALLINT UNSIGNED or SMALLINT(5) UNSIGNED
|
||||||
UnsignedSmallInt(Option<u64>),
|
UnsignedSmallInt(Option<u64>),
|
||||||
|
/// MySQL medium integer ([1]) with optional display width e.g. MEDIUMINT or MEDIUMINT(5)
|
||||||
|
///
|
||||||
|
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
|
||||||
|
MediumInt(Option<u64>),
|
||||||
|
/// Unsigned medium integer ([1]) with optional display width e.g. MEDIUMINT UNSIGNED or MEDIUMINT(5) UNSIGNED
|
||||||
|
///
|
||||||
|
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
|
||||||
|
UnsignedMediumInt(Option<u64>),
|
||||||
/// Integer with optional display width e.g. INT or INT(11)
|
/// Integer with optional display width e.g. INT or INT(11)
|
||||||
Int(Option<u64>),
|
Int(Option<u64>),
|
||||||
/// Integer with optional display width e.g. INTEGER or INTEGER(11)
|
/// Integer with optional display width e.g. INTEGER or INTEGER(11)
|
||||||
|
@ -141,6 +149,12 @@ impl fmt::Display for DataType {
|
||||||
DataType::UnsignedSmallInt(zerofill) => {
|
DataType::UnsignedSmallInt(zerofill) => {
|
||||||
format_type_with_optional_length(f, "SMALLINT", zerofill, true)
|
format_type_with_optional_length(f, "SMALLINT", zerofill, true)
|
||||||
}
|
}
|
||||||
|
DataType::MediumInt(zerofill) => {
|
||||||
|
format_type_with_optional_length(f, "MEDIUMINT", zerofill, false)
|
||||||
|
}
|
||||||
|
DataType::UnsignedMediumInt(zerofill) => {
|
||||||
|
format_type_with_optional_length(f, "MEDIUMINT", zerofill, true)
|
||||||
|
}
|
||||||
DataType::Int(zerofill) => format_type_with_optional_length(f, "INT", zerofill, false),
|
DataType::Int(zerofill) => format_type_with_optional_length(f, "INT", zerofill, false),
|
||||||
DataType::UnsignedInt(zerofill) => {
|
DataType::UnsignedInt(zerofill) => {
|
||||||
format_type_with_optional_length(f, "INT", zerofill, true)
|
format_type_with_optional_length(f, "INT", zerofill, true)
|
||||||
|
|
|
@ -325,6 +325,7 @@ define_keywords!(
|
||||||
MATCHED,
|
MATCHED,
|
||||||
MATERIALIZED,
|
MATERIALIZED,
|
||||||
MAX,
|
MAX,
|
||||||
|
MEDIUMINT,
|
||||||
MEMBER,
|
MEMBER,
|
||||||
MERGE,
|
MERGE,
|
||||||
METADATA,
|
METADATA,
|
||||||
|
|
|
@ -3360,6 +3360,14 @@ impl<'a> Parser<'a> {
|
||||||
Ok(DataType::SmallInt(optional_precision?))
|
Ok(DataType::SmallInt(optional_precision?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Keyword::MEDIUMINT => {
|
||||||
|
let optional_precision = self.parse_optional_precision();
|
||||||
|
if self.parse_keyword(Keyword::UNSIGNED) {
|
||||||
|
Ok(DataType::UnsignedMediumInt(optional_precision?))
|
||||||
|
} else {
|
||||||
|
Ok(DataType::MediumInt(optional_precision?))
|
||||||
|
}
|
||||||
|
}
|
||||||
Keyword::INT => {
|
Keyword::INT => {
|
||||||
let optional_precision = self.parse_optional_precision();
|
let optional_precision = self.parse_optional_precision();
|
||||||
if self.parse_keyword(Keyword::UNSIGNED) {
|
if self.parse_keyword(Keyword::UNSIGNED) {
|
||||||
|
|
|
@ -1623,6 +1623,11 @@ fn parse_cast() {
|
||||||
expr_from_projection(only(&select.projection))
|
expr_from_projection(only(&select.projection))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
one_statement_parses_to(
|
||||||
|
"SELECT CAST(id AS MEDIUMINT) FROM customer",
|
||||||
|
"SELECT CAST(id AS MEDIUMINT) FROM customer",
|
||||||
|
);
|
||||||
|
|
||||||
one_statement_parses_to(
|
one_statement_parses_to(
|
||||||
"SELECT CAST(id AS BIGINT) FROM customer",
|
"SELECT CAST(id AS BIGINT) FROM customer",
|
||||||
"SELECT CAST(id AS BIGINT) FROM customer",
|
"SELECT CAST(id AS BIGINT) FROM customer",
|
||||||
|
|
|
@ -552,7 +552,7 @@ fn parse_escaped_string() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_table_with_minimum_display_width() {
|
fn parse_create_table_with_minimum_display_width() {
|
||||||
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_int INT(11), bar_bigint BIGINT(20))";
|
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_mediumint MEDIUMINT(6), bar_int INT(11), bar_bigint BIGINT(20))";
|
||||||
match mysql().verified_stmt(sql) {
|
match mysql().verified_stmt(sql) {
|
||||||
Statement::CreateTable { name, columns, .. } => {
|
Statement::CreateTable { name, columns, .. } => {
|
||||||
assert_eq!(name.to_string(), "foo");
|
assert_eq!(name.to_string(), "foo");
|
||||||
|
@ -570,6 +570,12 @@ fn parse_create_table_with_minimum_display_width() {
|
||||||
collation: None,
|
collation: None,
|
||||||
options: vec![],
|
options: vec![],
|
||||||
},
|
},
|
||||||
|
ColumnDef {
|
||||||
|
name: Ident::new("bar_mediumint"),
|
||||||
|
data_type: DataType::MediumInt(Some(6)),
|
||||||
|
collation: None,
|
||||||
|
options: vec![],
|
||||||
|
},
|
||||||
ColumnDef {
|
ColumnDef {
|
||||||
name: Ident::new("bar_int"),
|
name: Ident::new("bar_int"),
|
||||||
data_type: DataType::Int(Some(11)),
|
data_type: DataType::Int(Some(11)),
|
||||||
|
@ -592,7 +598,7 @@ fn parse_create_table_with_minimum_display_width() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_table_unsigned() {
|
fn parse_create_table_unsigned() {
|
||||||
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3) UNSIGNED, bar_smallint SMALLINT(5) UNSIGNED, bar_int INT(11) UNSIGNED, bar_bigint BIGINT(20) UNSIGNED)";
|
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3) UNSIGNED, bar_smallint SMALLINT(5) UNSIGNED, bar_mediumint MEDIUMINT(13) UNSIGNED, bar_int INT(11) UNSIGNED, bar_bigint BIGINT(20) UNSIGNED)";
|
||||||
match mysql().verified_stmt(sql) {
|
match mysql().verified_stmt(sql) {
|
||||||
Statement::CreateTable { name, columns, .. } => {
|
Statement::CreateTable { name, columns, .. } => {
|
||||||
assert_eq!(name.to_string(), "foo");
|
assert_eq!(name.to_string(), "foo");
|
||||||
|
@ -610,6 +616,12 @@ fn parse_create_table_unsigned() {
|
||||||
collation: None,
|
collation: None,
|
||||||
options: vec![],
|
options: vec![],
|
||||||
},
|
},
|
||||||
|
ColumnDef {
|
||||||
|
name: Ident::new("bar_mediumint"),
|
||||||
|
data_type: DataType::UnsignedMediumInt(Some(13)),
|
||||||
|
collation: None,
|
||||||
|
options: vec![],
|
||||||
|
},
|
||||||
ColumnDef {
|
ColumnDef {
|
||||||
name: Ident::new("bar_int"),
|
name: Ident::new("bar_int"),
|
||||||
data_type: DataType::UnsignedInt(Some(11)),
|
data_type: DataType::UnsignedInt(Some(11)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue