-
Notifications
You must be signed in to change notification settings - Fork 640
Add PostgreSQL CREATE USER
and ALTER USER
support
#2015
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ pub use self::data_type::{ | |
ExactNumberInfo, IntervalFields, StructBracketKind, TimezoneInfo, | ||
}; | ||
pub use self::dcl::{ | ||
AlterRoleOperation, ResetConfig, RoleOption, SecondaryRoles, SetConfigValue, Use, | ||
AlterRoleOperation, ResetConfig, RoleKeyword, RoleOption, SecondaryRoles, SetConfigValue, Use, | ||
}; | ||
pub use self::ddl::{ | ||
AlterColumnOperation, AlterConnectorOwner, AlterIndexOperation, AlterPolicyOperation, | ||
|
@@ -3314,6 +3314,8 @@ pub enum Statement { | |
CreateRole { | ||
names: Vec<ObjectName>, | ||
if_not_exists: bool, | ||
/// Whether ROLE or USER keyword was used | ||
keyword: RoleKeyword, | ||
Comment on lines
+3317
to
+3318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use something like this representation instead? I think its a somewhat more invasive changes but clearer API wise. struct CreateUserOrRole { names: Vec<ObjectName>, if_not_exists: bool, // Postgres login: Option<bool>, inherit: Option<bool>, // ... } Statement::CreateUser(CreateUserOrRole) Statement::CreateRole(CreateUserOrRole) struct AlterUserOrRole { name: Ident } Statement::AlterUser(AlterUserOrRole) Statement::AlterRole(AlterUserOrRole) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a namespace problem here, because there's already a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I'm not sure I followed, do we mean snowflake has CreateUser supported by the parser already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but as far as I understand, it's a very different syntax / semantics. Postgres "USER" is really just an alias for "ROLE", and Postgres semantics are currently handled by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this would probably need a refactor so that all dialects use the same structures for |
||
// Postgres | ||
login: Option<bool>, | ||
inherit: Option<bool>, | ||
|
@@ -3421,6 +3423,8 @@ pub enum Statement { | |
/// ``` | ||
AlterRole { | ||
name: Ident, | ||
/// Whether ROLE or USER keyword was used | ||
keyword: RoleKeyword, | ||
operation: AlterRoleOperation, | ||
}, | ||
/// ```sql | ||
|
@@ -5279,6 +5283,7 @@ impl fmt::Display for Statement { | |
Statement::CreateRole { | ||
names, | ||
if_not_exists, | ||
keyword, | ||
inherit, | ||
login, | ||
bypassrls, | ||
|
@@ -5298,7 +5303,7 @@ impl fmt::Display for Statement { | |
} => { | ||
write!( | ||
f, | ||
"CREATE ROLE {if_not_exists}{names}{superuser}{create_db}{create_role}{inherit}{login}{replication}{bypassrls}", | ||
"CREATE {keyword} {if_not_exists}{names}{superuser}{create_db}{create_role}{inherit}{login}{replication}{bypassrls}", | ||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" }, | ||
names = display_separated(names, ", "), | ||
superuser = match *superuser { | ||
|
@@ -5337,6 +5342,7 @@ impl fmt::Display for Statement { | |
None => "" | ||
} | ||
)?; | ||
|
||
if let Some(limit) = connection_limit { | ||
write!(f, " CONNECTION LIMIT {limit}")?; | ||
} | ||
|
@@ -5506,8 +5512,12 @@ impl fmt::Display for Statement { | |
Statement::AlterType(AlterType { name, operation }) => { | ||
write!(f, "ALTER TYPE {name} {operation}") | ||
} | ||
Statement::AlterRole { name, operation } => { | ||
write!(f, "ALTER ROLE {name} {operation}") | ||
Statement::AlterRole { | ||
name, | ||
keyword, | ||
operation, | ||
} => { | ||
write!(f, "ALTER {keyword} {name} {operation}") | ||
} | ||
Statement::AlterPolicy { | ||
name, | ||
|