Skip to content

Commit 8370b18

Browse files
committed
Add table identifier alias support to explain output
Tables with aliases in FROM clause now show (alias xxx) in TableIdentifier output.
1 parent cd167d1 commit 8370b18

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/explain/tables.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ func explainTableExpression(sb *strings.Builder, n *ast.TableExpression, indent
3838
} else if fn, ok := n.Table.(*ast.FunctionCall); ok && n.Alias != "" {
3939
// Table function with alias
4040
explainFunctionCallWithAlias(sb, fn, n.Alias, indent+" ", depth+1)
41+
} else if ti, ok := n.Table.(*ast.TableIdentifier); ok && n.Alias != "" {
42+
// Table identifier with alias
43+
explainTableIdentifierWithAlias(sb, ti, n.Alias, indent+" ")
4144
} else {
4245
Node(sb, n.Table, depth+1)
4346
}
4447
}
4548

49+
func explainTableIdentifierWithAlias(sb *strings.Builder, n *ast.TableIdentifier, alias string, indent string) {
50+
name := n.Table
51+
if n.Database != "" {
52+
name = n.Database + "." + n.Table
53+
}
54+
fmt.Fprintf(sb, "%sTableIdentifier %s (alias %s)\n", indent, name, alias)
55+
}
56+
4657
func explainTableIdentifier(sb *strings.Builder, n *ast.TableIdentifier, indent string) {
4758
name := n.Table
4859
if n.Database != "" {

0 commit comments

Comments
 (0)