Skip to content

Commit

Permalink
fix: record table definition for column DDL
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyang01 committed Aug 23, 2024
1 parent a86fa21 commit 3cd922f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
stdsql "database/sql"
"encoding/base64"
"fmt"
"strings"
"sync"

"github.com/dolthub/go-mysql-server/sql"
Expand Down Expand Up @@ -252,7 +253,7 @@ func (b *DuckBuilder) SaveTableDDL(ctx *sql.Context, table sql.Node, conn *stdsq
ddl = ctx.Query()
default:
showCtx := ctx.WithQuery("SHOW CREATE TABLE " + table.(sql.Nameable).Name())
showNode := plan.NewShowCreateTable(table, false)
showNode, _ := plan.NewShowCreateTable(table, false).WithTargetSchema(table.Schema())
iter, err := b.base.Build(showCtx, showNode, nil)
if err != nil {
return err
Expand All @@ -264,7 +265,12 @@ func (b *DuckBuilder) SaveTableDDL(ctx *sql.Context, table sql.Node, conn *stdsq
if len(rows) == 0 {
return fmt.Errorf("no rows returned from SHOW CREATE TABLE")
}
ddl = rows[0][1].(string)

var lines []string
for _, row := range rows {
lines = append(lines, row[1].(string))
}
ddl = strings.Join(lines, "\n")
}

encoded := base64.StdEncoding.EncodeToString([]byte(ddl))
Expand Down

0 comments on commit 3cd922f

Please sign in to comment.