@@ -9,7 +9,9 @@ pub(crate) enum NameRefClass {
99 DropView ,
1010 DropMaterializedView ,
1111 DropSequence ,
12+ SequenceOwnedByColumn ,
1213 Tablespace ,
14+ DropDatabase ,
1315 ForeignKeyTable ,
1416 ForeignKeyColumn ,
1517 ForeignKeyLocalColumn ,
@@ -32,6 +34,7 @@ pub(crate) enum NameRefClass {
3234 CreateSchema ,
3335 CreateIndex ,
3436 CreateIndexColumn ,
37+ DefaultConstraintFunctionCall ,
3538 SelectFunctionCall ,
3639 SelectFromTable ,
3740 SelectColumn ,
@@ -46,6 +49,7 @@ pub(crate) enum NameRefClass {
4649 UpdateWhereColumn ,
4750 UpdateSetColumn ,
4851 UpdateFromTable ,
52+ JoinUsingColumn ,
4953 SchemaQualifier ,
5054 TypeReference ,
5155}
@@ -56,6 +60,7 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
5660 let mut in_column_list = false ;
5761 let mut in_where_clause = false ;
5862 let mut in_from_clause = false ;
63+ let mut in_on_clause = false ;
5964 let mut in_set_clause = false ;
6065 let mut in_constraint_exclusion_list = false ;
6166 let mut in_constraint_include_clause = false ;
@@ -83,11 +88,15 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
8388 . is_some ( ) ;
8489
8590 let mut in_from_clause = false ;
91+ let mut in_on_clause = false ;
8692 for ancestor in parent. ancestors ( ) {
93+ if ast:: OnClause :: can_cast ( ancestor. kind ( ) ) {
94+ in_on_clause = true ;
95+ }
8796 if ast:: FromClause :: can_cast ( ancestor. kind ( ) ) {
8897 in_from_clause = true ;
8998 }
90- if ast:: Select :: can_cast ( ancestor. kind ( ) ) && !in_from_clause {
99+ if ast:: Select :: can_cast ( ancestor. kind ( ) ) && ( !in_from_clause || in_on_clause ) {
91100 if is_function_call || is_schema_table_col {
92101 return Some ( NameRefClass :: SchemaQualifier ) ;
93102 } else {
@@ -119,15 +128,19 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
119128 . is_some ( ) ;
120129
121130 let mut in_from_clause = false ;
131+ let mut in_on_clause = false ;
122132 let mut in_cast_expr = false ;
123133 for ancestor in parent. ancestors ( ) {
134+ if ast:: OnClause :: can_cast ( ancestor. kind ( ) ) {
135+ in_on_clause = true ;
136+ }
124137 if ast:: CastExpr :: can_cast ( ancestor. kind ( ) ) {
125138 in_cast_expr = true ;
126139 }
127140 if ast:: FromClause :: can_cast ( ancestor. kind ( ) ) {
128141 in_from_clause = true ;
129142 }
130- if ast:: Select :: can_cast ( ancestor. kind ( ) ) && !in_from_clause {
143+ if ast:: Select :: can_cast ( ancestor. kind ( ) ) && ( !in_from_clause || in_on_clause ) {
131144 if in_cast_expr {
132145 return Some ( NameRefClass :: TypeReference ) ;
133146 }
@@ -191,6 +204,15 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
191204 if ast:: DropSequence :: can_cast ( ancestor. kind ( ) ) {
192205 return Some ( NameRefClass :: DropSequence ) ;
193206 }
207+ if ast:: DropDatabase :: can_cast ( ancestor. kind ( ) ) {
208+ return Some ( NameRefClass :: DropDatabase ) ;
209+ }
210+ if let Some ( sequence_option) = ast:: SequenceOption :: cast ( ancestor. clone ( ) )
211+ && sequence_option. owned_token ( ) . is_some ( )
212+ && sequence_option. by_token ( ) . is_some ( )
213+ {
214+ return Some ( NameRefClass :: SequenceOwnedByColumn ) ;
215+ }
194216 if ast:: DropTablespace :: can_cast ( ancestor. kind ( ) )
195217 || ast:: Tablespace :: can_cast ( ancestor. kind ( ) )
196218 || ast:: SetTablespace :: can_cast ( ancestor. kind ( ) )
@@ -296,14 +318,20 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
296318 if ast:: CallExpr :: can_cast ( ancestor. kind ( ) ) {
297319 in_call_expr = true ;
298320 }
321+ if ast:: DefaultConstraint :: can_cast ( ancestor. kind ( ) ) && in_call_expr && !in_arg_list {
322+ return Some ( NameRefClass :: DefaultConstraintFunctionCall ) ;
323+ }
324+ if ast:: OnClause :: can_cast ( ancestor. kind ( ) ) {
325+ in_on_clause = true ;
326+ }
299327 if ast:: FromClause :: can_cast ( ancestor. kind ( ) ) {
300328 in_from_clause = true ;
301329 }
302330 if ast:: Select :: can_cast ( ancestor. kind ( ) ) {
303331 if in_call_expr && !in_arg_list {
304332 return Some ( NameRefClass :: SelectFunctionCall ) ;
305333 }
306- if in_from_clause {
334+ if in_from_clause && !in_on_clause {
307335 return Some ( NameRefClass :: SelectFromTable ) ;
308336 }
309337 // Classify as SelectColumn for target list, WHERE, ORDER BY, GROUP BY, etc.
@@ -331,6 +359,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
331359 }
332360 return Some ( NameRefClass :: InsertTable ) ;
333361 }
362+ if ast:: JoinUsingClause :: can_cast ( ancestor. kind ( ) ) && in_column_list {
363+ return Some ( NameRefClass :: JoinUsingColumn ) ;
364+ }
334365 if ast:: WhereClause :: can_cast ( ancestor. kind ( ) ) {
335366 in_where_clause = true ;
336367 }
@@ -371,6 +402,7 @@ pub(crate) enum NameClass {
371402 CreateIndex ( ast:: CreateIndex ) ,
372403 CreateSequence ( ast:: CreateSequence ) ,
373404 CreateTablespace ( ast:: CreateTablespace ) ,
405+ CreateDatabase ( ast:: CreateDatabase ) ,
374406 CreateType ( ast:: CreateType ) ,
375407 CreateFunction ( ast:: CreateFunction ) ,
376408 CreateAggregate ( ast:: CreateAggregate ) ,
@@ -411,6 +443,9 @@ pub(crate) fn classify_name(name: &ast::Name) -> Option<NameClass> {
411443 if let Some ( create_tablespace) = ast:: CreateTablespace :: cast ( ancestor. clone ( ) ) {
412444 return Some ( NameClass :: CreateTablespace ( create_tablespace) ) ;
413445 }
446+ if let Some ( create_database) = ast:: CreateDatabase :: cast ( ancestor. clone ( ) ) {
447+ return Some ( NameClass :: CreateDatabase ( create_database) ) ;
448+ }
414449 if let Some ( create_type) = ast:: CreateType :: cast ( ancestor. clone ( ) ) {
415450 return Some ( NameClass :: CreateType ( create_type) ) ;
416451 }
0 commit comments