@@ -8,6 +8,20 @@ pub(crate) enum NameRefClass {
88 DropType ,
99 DropView ,
1010 DropMaterializedView ,
11+ DropSequence ,
12+ ForeignKeyTable ,
13+ ForeignKeyColumn ,
14+ ForeignKeyLocalColumn ,
15+ CheckConstraintColumn ,
16+ GeneratedColumn ,
17+ UniqueConstraintColumn ,
18+ PrimaryKeyConstraintColumn ,
19+ NotNullConstraintColumn ,
20+ ExcludeConstraintColumn ,
21+ PartitionByColumn ,
22+ PartitionOfTable ,
23+ LikeTable ,
24+ InheritsTable ,
1125 DropFunction ,
1226 DropAggregate ,
1327 DropProcedure ,
@@ -36,13 +50,16 @@ pub(crate) enum NameRefClass {
3650}
3751
3852pub ( crate ) fn classify_name_ref ( name_ref : & ast:: NameRef ) -> Option < NameRefClass > {
39- let mut in_partition_item = false ;
4053 let mut in_call_expr = false ;
4154 let mut in_arg_list = false ;
4255 let mut in_column_list = false ;
4356 let mut in_where_clause = false ;
4457 let mut in_from_clause = false ;
4558 let mut in_set_clause = false ;
59+ let mut in_constraint_exclusion_list = false ;
60+ let mut in_constraint_include_clause = false ;
61+ let mut in_constraint_where_clause = false ;
62+ let mut in_partition_item = false ;
4663
4764 // TODO: can we combine this if and the one that follows?
4865 if let Some ( parent) = name_ref. syntax ( ) . parent ( )
@@ -170,6 +187,62 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
170187 if ast:: DropMaterializedView :: can_cast ( ancestor. kind ( ) ) {
171188 return Some ( NameRefClass :: DropMaterializedView ) ;
172189 }
190+ if ast:: DropSequence :: can_cast ( ancestor. kind ( ) ) {
191+ return Some ( NameRefClass :: DropSequence ) ;
192+ }
193+ if let Some ( foreign_key) = ast:: ForeignKeyConstraint :: cast ( ancestor. clone ( ) ) {
194+ if in_column_list {
195+ // TODO: ast is too "flat" here, we need a unique node for to
196+ // and from columns to differentiate which would help us avoid
197+ // this
198+ if let Some ( to_columns) = foreign_key. to_columns ( )
199+ && to_columns
200+ . syntax ( )
201+ . text_range ( )
202+ . contains_range ( name_ref. syntax ( ) . text_range ( ) )
203+ {
204+ return Some ( NameRefClass :: ForeignKeyColumn ) ;
205+ }
206+ if let Some ( from_columns) = foreign_key. from_columns ( )
207+ && from_columns
208+ . syntax ( )
209+ . text_range ( )
210+ . contains_range ( name_ref. syntax ( ) . text_range ( ) )
211+ {
212+ return Some ( NameRefClass :: ForeignKeyLocalColumn ) ;
213+ }
214+ } else {
215+ return Some ( NameRefClass :: ForeignKeyTable ) ;
216+ }
217+ }
218+ if ast:: CheckConstraint :: can_cast ( ancestor. kind ( ) ) {
219+ return Some ( NameRefClass :: CheckConstraintColumn ) ;
220+ }
221+ if ast:: GeneratedConstraint :: can_cast ( ancestor. kind ( ) ) {
222+ return Some ( NameRefClass :: GeneratedColumn ) ;
223+ }
224+ if in_column_list && ast:: UniqueConstraint :: can_cast ( ancestor. kind ( ) ) {
225+ return Some ( NameRefClass :: UniqueConstraintColumn ) ;
226+ }
227+ if in_column_list && ast:: PrimaryKeyConstraint :: can_cast ( ancestor. kind ( ) ) {
228+ return Some ( NameRefClass :: PrimaryKeyConstraintColumn ) ;
229+ }
230+ if ast:: NotNullConstraint :: can_cast ( ancestor. kind ( ) ) {
231+ return Some ( NameRefClass :: NotNullConstraintColumn ) ;
232+ }
233+ if ( in_constraint_exclusion_list
234+ || in_constraint_include_clause
235+ || in_constraint_where_clause)
236+ && ast:: ExcludeConstraint :: can_cast ( ancestor. kind ( ) )
237+ {
238+ return Some ( NameRefClass :: ExcludeConstraintColumn ) ;
239+ }
240+ if ast:: LikeClause :: can_cast ( ancestor. kind ( ) ) {
241+ return Some ( NameRefClass :: LikeTable ) ;
242+ }
243+ if ast:: Inherits :: can_cast ( ancestor. kind ( ) ) {
244+ return Some ( NameRefClass :: InheritsTable ) ;
245+ }
173246 if ast:: CastExpr :: can_cast ( ancestor. kind ( ) ) && in_type {
174247 return Some ( NameRefClass :: TypeReference ) ;
175248 }
@@ -197,15 +270,18 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
197270 {
198271 return Some ( NameRefClass :: CreateSchema ) ;
199272 }
200- if ast:: PartitionItem :: can_cast ( ancestor. kind ( ) ) {
201- in_partition_item = true ;
202- }
203273 if ast:: CreateIndex :: can_cast ( ancestor. kind ( ) ) {
204274 if in_partition_item {
205275 return Some ( NameRefClass :: CreateIndexColumn ) ;
206276 }
207277 return Some ( NameRefClass :: CreateIndex ) ;
208278 }
279+ if in_partition_item && ast:: CreateTable :: can_cast ( ancestor. kind ( ) ) {
280+ return Some ( NameRefClass :: PartitionByColumn ) ;
281+ }
282+ if ast:: PartitionOf :: can_cast ( ancestor. kind ( ) ) {
283+ return Some ( NameRefClass :: PartitionOfTable ) ;
284+ }
209285 if ast:: ArgList :: can_cast ( ancestor. kind ( ) ) {
210286 in_arg_list = true ;
211287 }
@@ -229,6 +305,18 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
229305 if ast:: ColumnList :: can_cast ( ancestor. kind ( ) ) {
230306 in_column_list = true ;
231307 }
308+ if ast:: ConstraintExclusionList :: can_cast ( ancestor. kind ( ) ) {
309+ in_constraint_exclusion_list = true ;
310+ }
311+ if ast:: ConstraintIncludeClause :: can_cast ( ancestor. kind ( ) ) {
312+ in_constraint_include_clause = true ;
313+ }
314+ if ast:: WhereConditionClause :: can_cast ( ancestor. kind ( ) ) {
315+ in_constraint_where_clause = true ;
316+ }
317+ if ast:: PartitionItem :: can_cast ( ancestor. kind ( ) ) {
318+ in_partition_item = true ;
319+ }
232320 if ast:: Insert :: can_cast ( ancestor. kind ( ) ) {
233321 if in_column_list {
234322 return Some ( NameRefClass :: InsertColumn ) ;
@@ -273,6 +361,7 @@ pub(crate) enum NameClass {
273361 CreateTable ( ast:: CreateTable ) ,
274362 WithTable ( ast:: WithTable ) ,
275363 CreateIndex ( ast:: CreateIndex ) ,
364+ CreateSequence ( ast:: CreateSequence ) ,
276365 CreateType ( ast:: CreateType ) ,
277366 CreateFunction ( ast:: CreateFunction ) ,
278367 CreateAggregate ( ast:: CreateAggregate ) ,
@@ -307,6 +396,9 @@ pub(crate) fn classify_name(name: &ast::Name) -> Option<NameClass> {
307396 if let Some ( create_index) = ast:: CreateIndex :: cast ( ancestor. clone ( ) ) {
308397 return Some ( NameClass :: CreateIndex ( create_index) ) ;
309398 }
399+ if let Some ( create_sequence) = ast:: CreateSequence :: cast ( ancestor. clone ( ) ) {
400+ return Some ( NameClass :: CreateSequence ( create_sequence) ) ;
401+ }
310402 if let Some ( create_type) = ast:: CreateType :: cast ( ancestor. clone ( ) ) {
311403 return Some ( NameClass :: CreateType ( create_type) ) ;
312404 }
0 commit comments