dialect/sql: improve support for subqueries (#3274)

This commit is contained in:
Pedro Henrique
2023-01-26 04:43:07 -03:00
committed by GitHub
parent 5e852a16f7
commit 604c4942a4
2 changed files with 30 additions and 1 deletions

View File

@@ -2367,7 +2367,25 @@ func (s *Selector) Table() *SelectTable {
if len(s.from) == 0 {
return nil
}
return s.from[0].(*SelectTable)
return selectTable(s.from[0])
}
// selectTable returns a *SelectTable from the given TableView.
func selectTable(tb TableView) *SelectTable {
if tb == nil {
return nil
}
switch view := tb.(type) {
case *SelectTable:
return view
case *Selector:
if len(view.from) == 0 {
return nil
}
return selectTable(view.from[0])
default:
panic(fmt.Sprintf("unhandled TableView type %T", tb))
}
}
// TableName returns the name of the selected table or alias of selector.