MCPcopy Create free account
hub / github.com/dolthub/doltgresql / DropCast

Method DropCast

core/casts/collection.go:468–501  ·  view source on GitHub ↗

DropCast drops an existing cast.

(ctx context.Context, castIDs ...id.Cast)

Source from the content-addressed store, hash-verified

466
467// DropCast drops an existing cast.
468func (pgc *Collection) DropCast(ctx context.Context, castIDs ...id.Cast) error {
469 if len(castIDs) == 0 {
470 return nil
471 }
472 // Check that each name exists before performing any deletions
473 for _, castID := range castIDs {
474 if _, ok := builtInCasts[castID]; ok {
475 return errors.Errorf(`cannot delete built-in cast from type %s to type %s`,
476 castID.SourceType().TypeName(), castID.TargetType().TypeName())
477 }
478 if ok, err := pgc.underlyingMap.Has(ctx, string(castID)); err != nil {
479 return err
480 } else if !ok {
481 return errors.Errorf(`cast from type %s to type %s does not exist`,
482 castID.SourceType().TypeName(), castID.TargetType().TypeName())
483 }
484 }
485
486 // Now we'll remove the casts from the map
487 mapEditor := pgc.underlyingMap.Editor()
488 for _, castID := range castIDs {
489 err := mapEditor.Delete(ctx, string(castID))
490 if err != nil {
491 return err
492 }
493 }
494 newMap, err := mapEditor.Flush(ctx)
495 if err != nil {
496 return err
497 }
498 pgc.underlyingMap = newMap
499 pgc.mapHash = pgc.underlyingMap.HashOf()
500 return nil
501}
502
503// resolveName returns the fully resolved name of the given cast. Returns an error if the name is ambiguous.
504func (pgc *Collection) resolveName(ctx context.Context, schemaName string, formattedName string) (id.Cast, error) {

Callers 3

DropRootObjectMethod · 0.95
RenameRootObjectMethod · 0.95
RowIterMethod · 0.80

Calls 7

TypeNameMethod · 0.80
SourceTypeMethod · 0.80
TargetTypeMethod · 0.80
FlushMethod · 0.80
ErrorfMethod · 0.65
HasMethod · 0.45
HashOfMethod · 0.45

Tested by

no test coverage detected