File tree Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Expand file tree Collapse file tree 3 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -1013,6 +1013,16 @@ pub enum Statement {
1013
1013
/// Note: this is a PostgreSQL-specific statement,
1014
1014
/// but may also compatible with other SQL.
1015
1015
Discard { object_type : DiscardObject } ,
1016
+ /// SET [ SESSION | LOCAL ] ROLE role_name
1017
+ ///
1018
+ /// Note: this is a PostgreSQL-specific statement,
1019
+ /// but may also compatible with other SQL.
1020
+ SetRole {
1021
+ local : bool ,
1022
+ // SESSION is the default if neither SESSION nor LOCAL appears.
1023
+ session : bool ,
1024
+ role_name : Option < Ident > ,
1025
+ } ,
1016
1026
/// SET <variable>
1017
1027
///
1018
1028
/// Note: this is not a standard SQL statement, but it is supported by at
@@ -1755,6 +1765,24 @@ impl fmt::Display for Statement {
1755
1765
write ! ( f, "DISCARD {object_type}" , object_type = object_type) ?;
1756
1766
Ok ( ( ) )
1757
1767
}
1768
+ Statement :: SetRole {
1769
+ local,
1770
+ session,
1771
+ role_name,
1772
+ } => {
1773
+ write ! (
1774
+ f,
1775
+ "SET {local}{session}ROLE" ,
1776
+ local = if * local { "LOCAL " } else { "" } ,
1777
+ session = if * session { "SESSION " } else { "" } ,
1778
+ ) ?;
1779
+ if let Some ( role_name) = role_name {
1780
+ write ! ( f, " {}" , role_name) ?;
1781
+ } else {
1782
+ f. write_str ( " NONE" ) ?;
1783
+ }
1784
+ Ok ( ( ) )
1785
+ }
1758
1786
Statement :: SetVariable { key_values } => {
1759
1787
f. write_str ( "SET " ) ?;
1760
1788
Original file line number Diff line number Diff line change @@ -3681,6 +3681,17 @@ impl<'a> Parser<'a> {
3681
3681
. to_vec ( ) ,
3682
3682
} ) ;
3683
3683
}
3684
+ } else if self . parse_keyword ( Keyword :: ROLE ) {
3685
+ let role_name = if self . parse_keyword ( Keyword :: NONE ) {
3686
+ None
3687
+ } else {
3688
+ Some ( self . parse_identifier ( ) ?)
3689
+ } ;
3690
+ return Ok ( Statement :: SetRole {
3691
+ local : modifier == Some ( Keyword :: LOCAL ) ,
3692
+ session : modifier == Some ( Keyword :: SESSION ) ,
3693
+ role_name,
3694
+ } ) ;
3684
3695
}
3685
3696
3686
3697
let mut key_values: Vec < SetVariableKeyValue > = vec ! [ ] ;
Original file line number Diff line number Diff line change @@ -906,6 +906,45 @@ fn parse_set() {
906
906
) ;
907
907
}
908
908
909
+ #[ test]
910
+ fn parse_set_role ( ) {
911
+ let stmt = pg_and_generic ( ) . verified_stmt ( "SET SESSION ROLE NONE" ) ;
912
+ assert_eq ! (
913
+ stmt,
914
+ Statement :: SetRole {
915
+ local: false ,
916
+ session: true ,
917
+ role_name: None ,
918
+ }
919
+ ) ;
920
+
921
+ let stmt = pg_and_generic ( ) . verified_stmt ( "SET LOCAL ROLE \" rolename\" " ) ;
922
+ assert_eq ! (
923
+ stmt,
924
+ Statement :: SetRole {
925
+ local: true ,
926
+ session: false ,
927
+ role_name: Some ( Ident {
928
+ value: "rolename" . to_string( ) ,
929
+ quote_style: Some ( '\"' ) ,
930
+ } ) ,
931
+ }
932
+ ) ;
933
+
934
+ let stmt = pg_and_generic ( ) . verified_stmt ( "SET ROLE 'rolename'" ) ;
935
+ assert_eq ! (
936
+ stmt,
937
+ Statement :: SetRole {
938
+ local: false ,
939
+ session: false ,
940
+ role_name: Some ( Ident {
941
+ value: "rolename" . to_string( ) ,
942
+ quote_style: Some ( '\'' ) ,
943
+ } ) ,
944
+ }
945
+ ) ;
946
+ }
947
+
909
948
#[ test]
910
949
fn parse_show ( ) {
911
950
let stmt = pg_and_generic ( ) . verified_stmt ( "SHOW a a" ) ;
You can’t perform that action at this time.
0 commit comments