Skip to content

Commit

Permalink
fix: resolve duplicate fields generated when inheriting multiple tabl…
Browse files Browse the repository at this point in the history
…es (#2089)

* fix: resolve duplicate fields generated when inheriting multiple tables

* chore: comments

* fix: resolve duplicate fields generated when inheriting multiple tables (#1)
  • Loading branch information
ethan-xiao authored Jun 7, 2023
1 parent 99ecfff commit 0c340f2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/sql/catalog/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,21 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error {
}

tbl := Table{Rel: stmt.Name, Comment: stmt.Comment}
m := make(map[string]struct{}) // used to check for duplicate column names
for _, inheritTable := range stmt.Inherits {
t, _, err := schema.getTable(inheritTable)
if err != nil {
return err
}
tbl.Columns = append(tbl.Columns, t.Columns...)
// check and ignore duplicate columns
for _, col := range t.Columns {
if _, ok := m[col.Name]; ok {
continue
} else {
m[col.Name] = struct{}{}
tbl.Columns = append(tbl.Columns, col)
}
}
}

if stmt.ReferTable != nil && len(stmt.Cols) != 0 {
Expand Down

0 comments on commit 0c340f2

Please sign in to comment.