mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
Add CREATE DATABASE test and parsing (#451)
* Add test * Fix CreateDatabse parsing * Linting * Cleanup for code style
This commit is contained in:
parent
d38c30e9ff
commit
803fd6c970
3 changed files with 44 additions and 5 deletions
|
@ -1218,7 +1218,7 @@ impl fmt::Display for Statement {
|
|||
location,
|
||||
managed_location,
|
||||
} => {
|
||||
write!(f, "CREATE")?;
|
||||
write!(f, "CREATE DATABASE")?;
|
||||
if *if_not_exists {
|
||||
write!(f, " IF NOT EXISTS")?;
|
||||
}
|
||||
|
|
|
@ -1521,6 +1521,8 @@ impl<'a> Parser<'a> {
|
|||
self.parse_create_virtual_table()
|
||||
} else if self.parse_keyword(Keyword::SCHEMA) {
|
||||
self.parse_create_schema()
|
||||
} else if self.parse_keyword(Keyword::DATABASE) {
|
||||
self.parse_create_database()
|
||||
} else {
|
||||
self.expected("an object type after CREATE", self.peek_token())
|
||||
}
|
||||
|
|
|
@ -3297,10 +3297,9 @@ fn parse_scalar_subqueries() {
|
|||
assert_matches!(
|
||||
verified_expr(sql),
|
||||
Expr::BinaryOp {
|
||||
op: BinaryOperator::Plus, ..
|
||||
//left: box Subquery { .. },
|
||||
//right: box Subquery { .. },
|
||||
}
|
||||
op: BinaryOperator::Plus,
|
||||
..
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3386,6 +3385,44 @@ fn parse_exists_subquery() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_database() {
|
||||
let sql = "CREATE DATABASE mydb";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateDatabase {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
} => {
|
||||
assert_eq!("mydb", db_name.to_string());
|
||||
assert!(!if_not_exists);
|
||||
assert_eq!(None, location);
|
||||
assert_eq!(None, managed_location);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_database_ine() {
|
||||
let sql = "CREATE DATABASE IF NOT EXISTS mydb";
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateDatabase {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
} => {
|
||||
assert_eq!("mydb", db_name.to_string());
|
||||
assert!(if_not_exists);
|
||||
assert_eq!(None, location);
|
||||
assert_eq!(None, managed_location);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_view() {
|
||||
let sql = "CREATE VIEW myschema.myview AS SELECT foo FROM bar";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue