Skip to content

Commit

Permalink
Support DOUBLE data types with precision for Mysql (apache#1611)
Browse files Browse the repository at this point in the history
  • Loading branch information
artorias1024 authored Dec 19, 2024
1 parent eae5629 commit c973df3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub enum DataType {
/// [postgresql]: https://www.postgresql.org/docs/15/datatype.html
Float8,
/// Double
Double,
Double(ExactNumberInfo),
/// Double PRECISION e.g. [standard], [postgresql]
///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#approximate-numeric-type
Expand Down Expand Up @@ -508,7 +508,7 @@ impl fmt::Display for DataType {
DataType::Float4 => write!(f, "FLOAT4"),
DataType::Float32 => write!(f, "Float32"),
DataType::Float64 => write!(f, "FLOAT64"),
DataType::Double => write!(f, "DOUBLE"),
DataType::Double(info) => write!(f, "DOUBLE{info}"),
DataType::Float8 => write!(f, "FLOAT8"),
DataType::DoublePrecision => write!(f, "DOUBLE PRECISION"),
DataType::Bool => write!(f, "BOOL"),
Expand Down
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8115,7 +8115,9 @@ impl<'a> Parser<'a> {
if self.parse_keyword(Keyword::PRECISION) {
Ok(DataType::DoublePrecision)
} else {
Ok(DataType::Double)
Ok(DataType::Double(
self.parse_exact_number_optional_precision_scale()?,
))
}
}
Keyword::TINYINT => {
Expand Down
12 changes: 6 additions & 6 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,7 @@ fn parse_create_table() {
},
ColumnDef {
name: "lat".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![ColumnOptionDef {
name: None,
Expand All @@ -3018,7 +3018,7 @@ fn parse_create_table() {
},
ColumnDef {
name: "lng".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![],
},
Expand Down Expand Up @@ -3198,7 +3198,7 @@ fn parse_create_table_with_constraint_characteristics() {
},
ColumnDef {
name: "lat".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![ColumnOptionDef {
name: None,
Expand All @@ -3207,7 +3207,7 @@ fn parse_create_table_with_constraint_characteristics() {
},
ColumnDef {
name: "lng".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![],
},
Expand Down Expand Up @@ -3838,7 +3838,7 @@ fn parse_create_external_table() {
},
ColumnDef {
name: "lat".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![ColumnOptionDef {
name: None,
Expand All @@ -3847,7 +3847,7 @@ fn parse_create_external_table() {
},
ColumnDef {
name: "lng".into(),
data_type: DataType::Double,
data_type: DataType::Double(ExactNumberInfo::None),
collation: None,
options: vec![],
},
Expand Down
10 changes: 10 additions & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3022,3 +3022,13 @@ fn parse_longblob_type() {
fn parse_begin_without_transaction() {
mysql().verified_stmt("BEGIN");
}

#[test]
fn parse_double_precision() {
mysql().verified_stmt("CREATE TABLE foo (bar DOUBLE)");
mysql().verified_stmt("CREATE TABLE foo (bar DOUBLE(11,0))");
mysql().one_statement_parses_to(
"CREATE TABLE foo (bar DOUBLE(11, 0))",
"CREATE TABLE foo (bar DOUBLE(11,0))",
);
}

0 comments on commit c973df3

Please sign in to comment.