Adding DOUBLE PRECISION to data types, parsing it, and tests (#629)

This commit is contained in:
AugustoFKL 2022-09-28 17:26:11 -03:00 committed by GitHub
parent 6c8f31c367
commit 46b7c03788
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -67,8 +67,13 @@ pub enum DataType {
UnsignedBigInt(Option<u64>),
/// Floating point e.g. REAL
Real,
/// Double e.g. DOUBLE PRECISION
/// Double
Double,
/// Double PRECISION e.g. [standard], [postgresql]
///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#approximate-numeric-type
/// [postgresql]: https://www.postgresql.org/docs/current/datatype-numeric.html
DoublePrecision,
/// Boolean
Boolean,
/// Date
@ -154,6 +159,7 @@ impl fmt::Display for DataType {
}
DataType::Real => write!(f, "REAL"),
DataType::Double => write!(f, "DOUBLE"),
DataType::DoublePrecision => write!(f, "DOUBLE PRECISION"),
DataType::Boolean => write!(f, "BOOLEAN"),
DataType::Date => write!(f, "DATE"),
DataType::Time => write!(f, "TIME"),

View file

@ -3338,8 +3338,11 @@ impl<'a> Parser<'a> {
Keyword::FLOAT => Ok(DataType::Float(self.parse_optional_precision()?)),
Keyword::REAL => Ok(DataType::Real),
Keyword::DOUBLE => {
let _ = self.parse_keyword(Keyword::PRECISION);
Ok(DataType::Double)
if self.parse_keyword(Keyword::PRECISION) {
Ok(DataType::DoublePrecision)
} else {
Ok(DataType::Double)
}
}
Keyword::TINYINT => {
let optional_precision = self.parse_optional_precision();
@ -5241,4 +5244,18 @@ mod tests {
assert_eq!(ast.to_string(), sql.to_string());
});
}
// TODO add tests for all data types? https://github.com/sqlparser-rs/sqlparser-rs/issues/2
#[test]
fn test_parse_data_type() {
test_parse_data_type("DOUBLE PRECISION", "DOUBLE PRECISION");
test_parse_data_type("DOUBLE", "DOUBLE");
fn test_parse_data_type(input: &str, expected: &str) {
all_dialects().run_parser_method(input, |parser| {
let data_type = parser.parse_data_type().unwrap().to_string();
assert_eq!(data_type, expected);
});
}
}
}