CreateIndex implements sql.IndexAlterableTable.
(ctx *sql.Context, indexDef sql.IndexDef)
| 553 | } |
| 554 | |
| 555 | var _ sql.RowUpdater = (*EmptyTableEditor)(nil) |
| 556 | |
| 557 | // Updater implements sql.AlterableTable. |
| 558 | func (t *Table) Updater(ctx *sql.Context) sql.RowUpdater { |
| 559 | // Called when altering a table’s default value. No update needed as DuckDB handles it internally. |
| 560 | return &EmptyTableEditor{} |
| 561 | } |
| 562 | |
| 563 | // Inserter implements sql.InsertableTable. |
| 564 | func (t *Table) Inserter(*sql.Context) sql.RowInserter { |
| 565 | return &rowInserter{ |
| 566 | db: t.db.Name(), |
| 567 | table: t.name, |
| 568 | schema: t.schema.Schema, |
| 569 | hasPK: t.hasPrimaryKey, |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | // Deleter implements sql.DeletableTable. |
| 574 | func (t *Table) Deleter(*sql.Context) sql.RowDeleter { |
| 575 | return nil |
| 576 | } |
| 577 | |
| 578 | // Truncate implements sql.TruncateableTable. |
| 579 | func (t *Table) Truncate(ctx *sql.Context) (int, error) { |
| 580 | result, err := adapter.ExecCatalog(ctx, `TRUNCATE TABLE `+FullTableName(t.db.catalog, t.db.name, t.name)) |
| 581 | if err != nil { |
| 582 | return 0, err |
| 583 | } |
| 584 | affected, err := result.RowsAffected() |
| 585 | return int(affected), err |
| 586 | } |
| 587 | |
| 588 | // Replacer implements sql.ReplaceableTable. |
| 589 | func (t *Table) Replacer(*sql.Context) sql.RowReplacer { |
| 590 | hasKey := len(t.schema.PkOrdinals) > 0 || !sql.IsKeyless(t.schema.Schema) |
| 591 | return &rowInserter{ |
| 592 | db: t.db.Name(), |
| 593 | table: t.name, |
| 594 | schema: t.schema.Schema, |
| 595 | hasPK: t.hasPrimaryKey, |
| 596 | replace: hasKey, |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | // CreateIndex implements sql.IndexAlterableTable. |
| 601 | func (t *Table) CreateIndex(ctx *sql.Context, indexDef sql.IndexDef) error { |
| 602 | // Lock the table to ensure thread-safety during index creation |
| 603 | t.mu.Lock() |
| 604 | defer t.mu.Unlock() |
| 605 | |
| 606 | // https://github.com/apecloud/myduckserver/issues/272 |
| 607 | if isIndexCreationDisabled(ctx) { |
| 608 | return nil |
| 609 | } |
| 610 | |
| 611 | if indexDef.IsPrimary() { |
| 612 | return fmt.Errorf("primary key cannot be created with CreateIndex, use ALTER TABLE ... ADD PRIMARY KEY instead") |
nothing calls this directly
no test coverage detected