Skip to content

Commit f5fceb6

Browse files
committed
fix(sqlite): Extract columns from CREATE TABLE AS clause
1 parent 3ad8b20 commit f5fceb6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎internal/engine/sqlite/convert.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,21 @@ func columnTypeName(t *meyer.TypeName) string {
282282
}
283283

284284
func (c *cc) convertCreateTableStmt(n *meyer.CreateTableStmt) ast.Node {
285+
// CREATE TABLE ... AS SELECT takes its columns from the query, so it is
286+
// recorded as a relation defined by that query.
287+
if n.Select != nil {
288+
return &ast.CreateTableAsStmt{
289+
Query: c.convert(n.Select),
290+
Into: &ast.IntoClause{Rel: parseRangeVar(n.Name, nil)},
291+
IfNotExists: n.IfNotExists,
292+
}
293+
}
285294
stmt := &ast.CreateTableStmt{
286295
Name: parseTableName(n.Name),
287296
IfNotExists: n.IfNotExists,
288297
// The node models none of these, so a statement carrying them has
289298
// no faithful rendering and the formatter keeps it as written.
290-
Incomplete: n.Temp || n.Select != nil || len(n.Constraints) > 0 || len(n.Options) > 0,
299+
Incomplete: n.Temp || len(n.Constraints) > 0 || len(n.Options) > 0,
291300
}
292301
for _, def := range n.Columns {
293302
if !representableColumn(def) {

0 commit comments

Comments
 (0)