Skip to content

Commit 46b7c03

Browse files
authored
Adding DOUBLE PRECISION to data types, parsing it, and tests (#629)
1 parent 6c8f31c commit 46b7c03

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/ast/data_type.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ pub enum DataType {
6767
UnsignedBigInt(Option<u64>),
6868
/// Floating point e.g. REAL
6969
Real,
70-
/// Double e.g. DOUBLE PRECISION
70+
/// Double
7171
Double,
72+
/// Double PRECISION e.g. [standard], [postgresql]
73+
///
74+
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#approximate-numeric-type
75+
/// [postgresql]: https://www.postgresql.org/docs/current/datatype-numeric.html
76+
DoublePrecision,
7277
/// Boolean
7378
Boolean,
7479
/// Date
@@ -154,6 +159,7 @@ impl fmt::Display for DataType {
154159
}
155160
DataType::Real => write!(f, "REAL"),
156161
DataType::Double => write!(f, "DOUBLE"),
162+
DataType::DoublePrecision => write!(f, "DOUBLE PRECISION"),
157163
DataType::Boolean => write!(f, "BOOLEAN"),
158164
DataType::Date => write!(f, "DATE"),
159165
DataType::Time => write!(f, "TIME"),

src/parser.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,8 +3338,11 @@ impl<'a> Parser<'a> {
33383338
Keyword::FLOAT => Ok(DataType::Float(self.parse_optional_precision()?)),
33393339
Keyword::REAL => Ok(DataType::Real),
33403340
Keyword::DOUBLE => {
3341-
let _ = self.parse_keyword(Keyword::PRECISION);
3342-
Ok(DataType::Double)
3341+
if self.parse_keyword(Keyword::PRECISION) {
3342+
Ok(DataType::DoublePrecision)
3343+
} else {
3344+
Ok(DataType::Double)
3345+
}
33433346
}
33443347
Keyword::TINYINT => {
33453348
let optional_precision = self.parse_optional_precision();
@@ -5241,4 +5244,18 @@ mod tests {
52415244
assert_eq!(ast.to_string(), sql.to_string());
52425245
});
52435246
}
5247+
5248+
// TODO add tests for all data types? https://github.com/sqlparser-rs/sqlparser-rs/issues/2
5249+
#[test]
5250+
fn test_parse_data_type() {
5251+
test_parse_data_type("DOUBLE PRECISION", "DOUBLE PRECISION");
5252+
test_parse_data_type("DOUBLE", "DOUBLE");
5253+
5254+
fn test_parse_data_type(input: &str, expected: &str) {
5255+
all_dialects().run_parser_method(input, |parser| {
5256+
let data_type = parser.parse_data_type().unwrap().to_string();
5257+
assert_eq!(data_type, expected);
5258+
});
5259+
}
5260+
}
52445261
}

0 commit comments

Comments
 (0)