Skip to content

Commit cb6b879

Browse files
committed
Add PRIMARY KEY output to CREATE TABLE explain
Output PRIMARY KEY clause in Storage definition section
1 parent 866dd1c commit cb6b879

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/explain/statements.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
116116
}
117117
}
118118
}
119+
if len(n.PrimaryKey) > 0 {
120+
if len(n.PrimaryKey) == 1 {
121+
if ident, ok := n.PrimaryKey[0].(*ast.Identifier); ok {
122+
fmt.Fprintf(sb, "%s Identifier %s\n", indent, ident.Name())
123+
} else {
124+
Node(sb, n.PrimaryKey[0], depth+2)
125+
}
126+
} else {
127+
fmt.Fprintf(sb, "%s Function tuple (children %d)\n", indent, 1)
128+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.PrimaryKey))
129+
for _, p := range n.PrimaryKey {
130+
Node(sb, p, depth+4)
131+
}
132+
}
133+
}
119134
if len(n.Settings) > 0 {
120135
fmt.Fprintf(sb, "%s Set\n", indent)
121136
}

0 commit comments

Comments
 (0)