This is an automated email from the ASF dual-hosted git repository.
iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new c973df35 Support DOUBLE data types with precision for Mysql (#1611)
c973df35 is described below
commit c973df35d69f156acda80fa60c34f9f15d7ff104
Author: artorias1024 <[email protected]>
AuthorDate: Fri Dec 20 01:11:39 2024 +0800
Support DOUBLE data types with precision for Mysql (#1611)
---
src/ast/data_type.rs | 4 ++--
src/parser/mod.rs | 4 +++-
tests/sqlparser_common.rs | 12 ++++++------
tests/sqlparser_mysql.rs | 10 ++++++++++
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index b53b8f0d..02aa6cc9 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -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
@@ -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"),
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 570b2397..df4af538 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -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 => {
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index f18daa52..507c9c77 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -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,
@@ -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![],
},
@@ -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,
@@ -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![],
},
@@ -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,
@@ -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![],
},
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index bc7bf2f8..4a4e7961 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -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))",
+ );
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]