Skip to content

Commit

Permalink
Add test for optional WITH in CREATE ROLE (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Sep 27, 2022
1 parent 91087fc commit 2b21da2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Expand Up @@ -1229,7 +1229,7 @@ pub enum Statement {
///
/// Note: this is a MySQL-specific statement.
SetNamesDefault {},
/// SHOW FUNCTIONS
/// SHOW FUNCTIONS
///
/// Note: this is a Presto-specific statement.
ShowFunctions { filter: Option<ShowStatementFilter> },
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Expand Up @@ -2062,6 +2062,7 @@ impl<'a> Parser<'a> {
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let names = self.parse_comma_separated(Parser::parse_object_name)?;

// Parse optional WITH
let _ = self.parse_keyword(Keyword::WITH);

let optional_keywords = if dialect_of!(self is MsSqlDialect) {
Expand Down
17 changes: 17 additions & 0 deletions tests/sqlparser_postgres.rs
Expand Up @@ -1772,6 +1772,23 @@ fn parse_create_role() {
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
}

let sql = "CREATE ROLE abc WITH LOGIN PASSWORD NULL";
match pg().parse_sql_statements(sql).as_deref() {
Ok(
[Statement::CreateRole {
names,
login,
password,
..
}],
) => {
assert_eq_vec(&["abc"], names);
assert_eq!(*login, Some(true));
assert_eq!(*password, Some(Password::NullPassword));
}
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
}

let sql = "CREATE ROLE magician WITH SUPERUSER CREATEROLE NOCREATEDB BYPASSRLS INHERIT PASSWORD 'abcdef' LOGIN VALID UNTIL '2025-01-01' IN ROLE role1, role2 ROLE role3 ADMIN role4, role5 REPLICATION";
// Roundtrip order of optional parameters is not preserved
match pg().parse_sql_statements(sql).as_deref() {
Expand Down

0 comments on commit 2b21da2

Please sign in to comment.