@@ -28,7 +28,7 @@ use serde::{Deserialize, Serialize};
2828#[ cfg( feature = "visitor" ) ]
2929use sqlparser_derive:: { Visit , VisitMut } ;
3030
31- use super :: { Expr , Ident , Password } ;
31+ use super :: { display_comma_separated , Expr , Ident , Password } ;
3232use crate :: ast:: { display_separated, ObjectName } ;
3333
3434/// An option in `ROLE` statement.
@@ -204,12 +204,14 @@ impl fmt::Display for AlterRoleOperation {
204204#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
205205#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
206206pub enum Use {
207- Catalog ( ObjectName ) , // e.g. `USE CATALOG foo.bar`
208- Schema ( ObjectName ) , // e.g. `USE SCHEMA foo.bar`
209- Database ( ObjectName ) , // e.g. `USE DATABASE foo.bar`
210- Warehouse ( ObjectName ) , // e.g. `USE WAREHOUSE foo.bar`
211- Object ( ObjectName ) , // e.g. `USE foo.bar`
212- Default , // e.g. `USE DEFAULT`
207+ Catalog ( ObjectName ) , // e.g. `USE CATALOG foo.bar`
208+ Schema ( ObjectName ) , // e.g. `USE SCHEMA foo.bar`
209+ Database ( ObjectName ) , // e.g. `USE DATABASE foo.bar`
210+ Warehouse ( ObjectName ) , // e.g. `USE WAREHOUSE foo.bar`
211+ Role ( ObjectName ) , // e.g. `USE ROLE PUBLIC`
212+ SecondaryRoles ( SecondaryRoles ) , // e.g. `USE SECONDARY ROLES ALL`
213+ Object ( ObjectName ) , // e.g. `USE foo.bar`
214+ Default , // e.g. `USE DEFAULT`
213215}
214216
215217impl fmt:: Display for Use {
@@ -220,8 +222,33 @@ impl fmt::Display for Use {
220222 Use :: Schema ( name) => write ! ( f, "SCHEMA {}" , name) ,
221223 Use :: Database ( name) => write ! ( f, "DATABASE {}" , name) ,
222224 Use :: Warehouse ( name) => write ! ( f, "WAREHOUSE {}" , name) ,
225+ Use :: Role ( name) => write ! ( f, "ROLE {}" , name) ,
226+ Use :: SecondaryRoles ( secondary_roles) => {
227+ write ! ( f, "SECONDARY ROLES {}" , secondary_roles)
228+ }
223229 Use :: Object ( name) => write ! ( f, "{}" , name) ,
224230 Use :: Default => write ! ( f, "DEFAULT" ) ,
225231 }
226232 }
227233}
234+
235+ /// Snowflake `SECONDARY ROLES` USE variant
236+ /// See: <https://docs.snowflake.com/en/sql-reference/sql/use-secondary-roles>
237+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
238+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
239+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
240+ pub enum SecondaryRoles {
241+ All ,
242+ None ,
243+ List ( Vec < Ident > ) ,
244+ }
245+
246+ impl fmt:: Display for SecondaryRoles {
247+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
248+ match self {
249+ SecondaryRoles :: All => write ! ( f, "ALL" ) ,
250+ SecondaryRoles :: None => write ! ( f, "NONE" ) ,
251+ SecondaryRoles :: List ( roles) => write ! ( f, "{}" , display_comma_separated( roles) ) ,
252+ }
253+ }
254+ }
0 commit comments