Snowflake: Add support for CREATE USER (#1950)

This commit is contained in:
Yoav Cohen 2025-07-23 18:52:08 +03:00 committed by GitHub
parent 492184643a
commit 2ed2cbe291
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 281 additions and 85 deletions

View file

@ -4355,6 +4355,11 @@ pub enum Statement {
///
/// See [ReturnStatement]
Return(ReturnStatement),
/// ```sql
/// CREATE [OR REPLACE] USER <user> [IF NOT EXISTS]
/// ```
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-user)
CreateUser(CreateUser),
}
/// ```sql
@ -6193,6 +6198,7 @@ impl fmt::Display for Statement {
Statement::Return(r) => write!(f, "{r}"),
Statement::List(command) => write!(f, "LIST {command}"),
Statement::Remove(command) => write!(f, "REMOVE {command}"),
Statement::CreateUser(s) => write!(f, "{s}"),
}
}
}
@ -10125,6 +10131,50 @@ impl fmt::Display for MemberOf {
}
}
/// Creates a user
///
/// Syntax:
/// ```sql
/// CREATE [OR REPLACE] USER [IF NOT EXISTS] <name> [OPTIONS]
/// ```
///
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-user)
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct CreateUser {
pub or_replace: bool,
pub if_not_exists: bool,
pub name: Ident,
pub options: KeyValueOptions,
pub with_tags: bool,
pub tags: KeyValueOptions,
}
impl fmt::Display for CreateUser {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CREATE")?;
if self.or_replace {
write!(f, " OR REPLACE")?;
}
write!(f, " USER")?;
if self.if_not_exists {
write!(f, " IF NOT EXISTS")?;
}
write!(f, " {}", self.name)?;
if !self.options.options.is_empty() {
write!(f, " {}", self.options)?;
}
if !self.tags.options.is_empty() {
if self.with_tags {
write!(f, " WITH")?;
}
write!(f, " TAG ({})", self.tags)?;
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use crate::tokenizer::Location;