@@ -21,6 +21,7 @@ use super::RwPgResponse;
21
21
use crate :: binder:: Binder ;
22
22
use crate :: catalog:: root_catalog:: SchemaPath ;
23
23
use crate :: catalog:: table_catalog:: TableType ;
24
+ use crate :: catalog:: CatalogError ;
24
25
use crate :: error:: { ErrorCode , Result } ;
25
26
use crate :: handler:: HandlerArgs ;
26
27
use crate :: session:: SessionImpl ;
@@ -93,17 +94,31 @@ fn make_prost_privilege(
93
94
Binder :: resolve_schema_qualified_name ( db_name, name) ?;
94
95
let schema_path = SchemaPath :: new ( schema_name. as_deref ( ) , & search_path, user_name) ;
95
96
96
- let ( table, _) = reader. get_table_by_name ( db_name, schema_path, & table_name) ?;
97
- match table. table_type ( ) {
98
- TableType :: Table => { }
99
- _ => {
100
- return Err ( ErrorCode :: InvalidInputSyntax ( format ! (
101
- "{table_name} is not a table" ,
102
- ) )
103
- . into ( ) ) ;
97
+ match reader. get_table_by_name ( db_name, schema_path, & table_name) {
98
+ Ok ( ( table, _) ) => {
99
+ match table. table_type ( ) {
100
+ TableType :: Table => {
101
+ grant_objs. push ( PbObject :: TableId ( table. id ( ) . table_id ) ) ;
102
+ continue ;
103
+ }
104
+ _ => {
105
+ return Err ( ErrorCode :: InvalidInputSyntax ( format ! (
106
+ "{table_name} is not a table" ,
107
+ ) )
108
+ . into ( ) ) ;
109
+ }
110
+ } ;
111
+ }
112
+ Err ( CatalogError :: NotFound ( "table" , _) ) => {
113
+ let ( view, _) = reader
114
+ . get_view_by_name ( db_name, schema_path, & table_name)
115
+ . map_err ( |_| CatalogError :: NotFound ( "table" , table_name) ) ?;
116
+ grant_objs. push ( PbObject :: ViewId ( view. id ) ) ;
117
+ }
118
+ Err ( e) => {
119
+ return Err ( e. into ( ) ) ;
104
120
}
105
121
}
106
- grant_objs. push ( PbObject :: TableId ( table. id ( ) . table_id ) ) ;
107
122
}
108
123
}
109
124
GrantObjects :: Sources ( sources) => {
@@ -138,7 +153,7 @@ fn make_prost_privilege(
138
153
for schema in schemas {
139
154
let schema_name = Binder :: resolve_schema_name ( schema) ?;
140
155
let schema = reader. get_schema_by_name ( session. database ( ) , & schema_name) ?;
141
- grant_objs. push ( PbObject :: AllDmlTablesSchemaId ( schema. id ( ) ) ) ;
156
+ grant_objs. push ( PbObject :: AllDmlRelationsSchemaId ( schema. id ( ) ) ) ;
142
157
}
143
158
}
144
159
o => {
0 commit comments