Skip to content

Commit 0c340f2

Browse files
authored
fix: resolve duplicate fields generated when inheriting multiple tables (#2089)
* fix: resolve duplicate fields generated when inheriting multiple tables * chore: comments * fix: resolve duplicate fields generated when inheriting multiple tables (#1)
1 parent 99ecfff commit 0c340f2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/sql/catalog/table.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,21 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error {
240240
}
241241

242242
tbl := Table{Rel: stmt.Name, Comment: stmt.Comment}
243+
m := make(map[string]struct{}) // used to check for duplicate column names
243244
for _, inheritTable := range stmt.Inherits {
244245
t, _, err := schema.getTable(inheritTable)
245246
if err != nil {
246247
return err
247248
}
248-
tbl.Columns = append(tbl.Columns, t.Columns...)
249+
// check and ignore duplicate columns
250+
for _, col := range t.Columns {
251+
if _, ok := m[col.Name]; ok {
252+
continue
253+
} else {
254+
m[col.Name] = struct{}{}
255+
tbl.Columns = append(tbl.Columns, col)
256+
}
257+
}
249258
}
250259

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

0 commit comments

Comments
 (0)