Skip to content

Commit c973df3

Browse files
authored
Support DOUBLE data types with precision for Mysql (#1611)
1 parent eae5629 commit c973df3

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/ast/data_type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub enum DataType {
254254
/// [postgresql]: https://www.postgresql.org/docs/15/datatype.html
255255
Float8,
256256
/// Double
257-
Double,
257+
Double(ExactNumberInfo),
258258
/// Double PRECISION e.g. [standard], [postgresql]
259259
///
260260
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#approximate-numeric-type
@@ -508,7 +508,7 @@ impl fmt::Display for DataType {
508508
DataType::Float4 => write!(f, "FLOAT4"),
509509
DataType::Float32 => write!(f, "Float32"),
510510
DataType::Float64 => write!(f, "FLOAT64"),
511-
DataType::Double => write!(f, "DOUBLE"),
511+
DataType::Double(info) => write!(f, "DOUBLE{info}"),
512512
DataType::Float8 => write!(f, "FLOAT8"),
513513
DataType::DoublePrecision => write!(f, "DOUBLE PRECISION"),
514514
DataType::Bool => write!(f, "BOOL"),

src/parser/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8115,7 +8115,9 @@ impl<'a> Parser<'a> {
81158115
if self.parse_keyword(Keyword::PRECISION) {
81168116
Ok(DataType::DoublePrecision)
81178117
} else {
8118-
Ok(DataType::Double)
8118+
Ok(DataType::Double(
8119+
self.parse_exact_number_optional_precision_scale()?,
8120+
))
81198121
}
81208122
}
81218123
Keyword::TINYINT => {

tests/sqlparser_common.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ fn parse_create_table() {
30093009
},
30103010
ColumnDef {
30113011
name: "lat".into(),
3012-
data_type: DataType::Double,
3012+
data_type: DataType::Double(ExactNumberInfo::None),
30133013
collation: None,
30143014
options: vec![ColumnOptionDef {
30153015
name: None,
@@ -3018,7 +3018,7 @@ fn parse_create_table() {
30183018
},
30193019
ColumnDef {
30203020
name: "lng".into(),
3021-
data_type: DataType::Double,
3021+
data_type: DataType::Double(ExactNumberInfo::None),
30223022
collation: None,
30233023
options: vec![],
30243024
},
@@ -3198,7 +3198,7 @@ fn parse_create_table_with_constraint_characteristics() {
31983198
},
31993199
ColumnDef {
32003200
name: "lat".into(),
3201-
data_type: DataType::Double,
3201+
data_type: DataType::Double(ExactNumberInfo::None),
32023202
collation: None,
32033203
options: vec![ColumnOptionDef {
32043204
name: None,
@@ -3207,7 +3207,7 @@ fn parse_create_table_with_constraint_characteristics() {
32073207
},
32083208
ColumnDef {
32093209
name: "lng".into(),
3210-
data_type: DataType::Double,
3210+
data_type: DataType::Double(ExactNumberInfo::None),
32113211
collation: None,
32123212
options: vec![],
32133213
},
@@ -3838,7 +3838,7 @@ fn parse_create_external_table() {
38383838
},
38393839
ColumnDef {
38403840
name: "lat".into(),
3841-
data_type: DataType::Double,
3841+
data_type: DataType::Double(ExactNumberInfo::None),
38423842
collation: None,
38433843
options: vec![ColumnOptionDef {
38443844
name: None,
@@ -3847,7 +3847,7 @@ fn parse_create_external_table() {
38473847
},
38483848
ColumnDef {
38493849
name: "lng".into(),
3850-
data_type: DataType::Double,
3850+
data_type: DataType::Double(ExactNumberInfo::None),
38513851
collation: None,
38523852
options: vec![],
38533853
},

tests/sqlparser_mysql.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3022,3 +3022,13 @@ fn parse_longblob_type() {
30223022
fn parse_begin_without_transaction() {
30233023
mysql().verified_stmt("BEGIN");
30243024
}
3025+
3026+
#[test]
3027+
fn parse_double_precision() {
3028+
mysql().verified_stmt("CREATE TABLE foo (bar DOUBLE)");
3029+
mysql().verified_stmt("CREATE TABLE foo (bar DOUBLE(11,0))");
3030+
mysql().one_statement_parses_to(
3031+
"CREATE TABLE foo (bar DOUBLE(11, 0))",
3032+
"CREATE TABLE foo (bar DOUBLE(11,0))",
3033+
);
3034+
}

0 commit comments

Comments
 (0)