Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ast/data_type.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down
21 changes: 19 additions & 2 deletions src/parser.rs
Expand Up @@ -3319,8 +3319,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();
Expand Down Expand Up @@ -5211,4 +5214,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);
});
}
}
}