mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-09 18:04:59 +00:00
Support IF NOT EXISTS for CREATE SCHEMA (#276)
This is a Postgres-specific clause: https://www.postgresql.org/docs/12/sql-createschema.html Also add a test for `DROP SCHEMA IF EXISTS schema_name`, which is already supported in the parser.
This commit is contained in:
parent
926b03a31d
commit
1ac208307c
4 changed files with 46 additions and 4 deletions
|
@ -300,6 +300,33 @@ fn parse_bad_if_not_exists() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_schema_if_not_exists() {
|
||||
let sql = "CREATE SCHEMA IF NOT EXISTS schema_name";
|
||||
let ast = pg_and_generic().verified_stmt(sql);
|
||||
match ast {
|
||||
Statement::CreateSchema {
|
||||
if_not_exists: true,
|
||||
schema_name,
|
||||
} => assert_eq!("schema_name", schema_name.to_string()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_drop_schema_if_exists() {
|
||||
let sql = "DROP SCHEMA IF EXISTS schema_name";
|
||||
let ast = pg().verified_stmt(sql);
|
||||
match ast {
|
||||
Statement::Drop {
|
||||
object_type,
|
||||
if_exists: true,
|
||||
..
|
||||
} => assert_eq!(object_type, ObjectType::Schema),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_copy_example() {
|
||||
let sql = r#"COPY public.actor (actor_id, first_name, last_name, last_update, value) FROM stdin;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue