@@ -66,6 +66,7 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
6666 let mut in_constraint_include_clause = false ;
6767 let mut in_constraint_where_clause = false ;
6868 let mut in_partition_item = false ;
69+ let mut in_set_null_columns = false ;
6970
7071 // TODO: can we combine this if and the one that follows?
7172 if let Some ( parent) = name_ref. syntax ( ) . parent ( )
@@ -115,6 +116,7 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
115116 // ^^^
116117 . is_some_and ( |field_name_ref| field_name_ref. syntax ( ) == name_ref. syntax ( ) )
117118 // we're not inside a call expr
119+ && field_expr. star_token ( ) . is_none ( )
118120 && field_expr
119121 . syntax ( )
120122 . parent ( )
@@ -220,6 +222,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
220222 {
221223 return Some ( NameRefClass :: Tablespace ) ;
222224 }
225+ if ast:: SetNullColumns :: can_cast ( ancestor. kind ( ) ) {
226+ in_set_null_columns = true ;
227+ }
223228 if let Some ( foreign_key) = ast:: ForeignKeyConstraint :: cast ( ancestor. clone ( ) ) {
224229 if in_column_list {
225230 // TODO: ast is too "flat" here, we need a unique node for to
@@ -241,10 +246,31 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
241246 {
242247 return Some ( NameRefClass :: ForeignKeyLocalColumn ) ;
243248 }
249+ if in_set_null_columns {
250+ return Some ( NameRefClass :: ForeignKeyLocalColumn ) ;
251+ }
244252 } else {
245253 return Some ( NameRefClass :: ForeignKeyTable ) ;
246254 }
247255 }
256+ if let Some ( references_constraint) = ast:: ReferencesConstraint :: cast ( ancestor. clone ( ) ) {
257+ if let Some ( column_ref) = references_constraint. column ( )
258+ && column_ref
259+ . syntax ( )
260+ . text_range ( )
261+ . contains_range ( name_ref. syntax ( ) . text_range ( ) )
262+ {
263+ return Some ( NameRefClass :: ForeignKeyColumn ) ;
264+ }
265+ if let Some ( path) = references_constraint. table ( )
266+ && path
267+ . syntax ( )
268+ . text_range ( )
269+ . contains_range ( name_ref. syntax ( ) . text_range ( ) )
270+ {
271+ return Some ( NameRefClass :: ForeignKeyTable ) ;
272+ }
273+ }
248274 if ast:: CheckConstraint :: can_cast ( ancestor. kind ( ) ) {
249275 return Some ( NameRefClass :: CheckConstraintColumn ) ;
250276 }
0 commit comments