Skip to content

Commit 2b21da2

Browse files
authored
Add test for optional WITH in CREATE ROLE (#627)
1 parent 91087fc commit 2b21da2

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ pub enum Statement {
12291229
///
12301230
/// Note: this is a MySQL-specific statement.
12311231
SetNamesDefault {},
1232-
/// SHOW FUNCTIONS
1232+
/// SHOW FUNCTIONS
12331233
///
12341234
/// Note: this is a Presto-specific statement.
12351235
ShowFunctions { filter: Option<ShowStatementFilter> },

src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ impl<'a> Parser<'a> {
20622062
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
20632063
let names = self.parse_comma_separated(Parser::parse_object_name)?;
20642064

2065+
// Parse optional WITH
20652066
let _ = self.parse_keyword(Keyword::WITH);
20662067

20672068
let optional_keywords = if dialect_of!(self is MsSqlDialect) {

tests/sqlparser_postgres.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,23 @@ fn parse_create_role() {
17721772
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
17731773
}
17741774

1775+
let sql = "CREATE ROLE abc WITH LOGIN PASSWORD NULL";
1776+
match pg().parse_sql_statements(sql).as_deref() {
1777+
Ok(
1778+
[Statement::CreateRole {
1779+
names,
1780+
login,
1781+
password,
1782+
..
1783+
}],
1784+
) => {
1785+
assert_eq_vec(&["abc"], names);
1786+
assert_eq!(*login, Some(true));
1787+
assert_eq!(*password, Some(Password::NullPassword));
1788+
}
1789+
err => panic!("Failed to parse CREATE ROLE test case: {:?}", err),
1790+
}
1791+
17751792
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";
17761793
// Roundtrip order of optional parameters is not preserved
17771794
match pg().parse_sql_statements(sql).as_deref() {

0 commit comments

Comments
 (0)