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

Function nodeAlterTableComputed

server/ast/alter_table.go:447–494  ·  view source on GitHub ↗

nodeAlterTableComputed converts a tree.AlterTableComputed instance into an equivalent CREATE/ALTER SEQUENCE statement.

(ctx *Context, tableName tree.TableName, node *tree.AlterTableComputed)

Source from the content-addressed store, hash-verified

445
446// nodeAlterTableComputed converts a tree.AlterTableComputed instance into an equivalent CREATE/ALTER SEQUENCE statement.
447func nodeAlterTableComputed(ctx *Context, tableName tree.TableName, node *tree.AlterTableComputed) (vitess.Statement, error) {
448 if len(node.Defs) > 0 {
449 return NotYetSupportedError("ALTER TABLE variant is not yet supported")
450 }
451 var persistence tree.Persistence
452 var seqName tree.TableName
453 var trimmedOptions []tree.SequenceOption
454 switch def := node.AddDefs.(type) {
455 case *tree.ColumnComputedDef:
456 if def.Expr != nil {
457 return NotYetSupportedError("ALTER TABLE variant is not yet supported")
458 }
459 trimmedOptions = make([]tree.SequenceOption, 0, len(def.Options)+2)
460 for _, opt := range def.Options {
461 switch opt.Name {
462 case tree.SeqOptOwnedBy:
463 return NotYetSupportedError("OWNED BY is invalid here")
464 case tree.SeqOptRestart:
465 return NotYetSupportedError("RESTART is not yet supported")
466 case tree.SeqOptName:
467 seqName = opt.SeqName
468 case tree.SeqOptLogged:
469 persistence = tree.PersistencePermanent
470 case tree.SeqOptUnlogged:
471 persistence = tree.PersistenceUnlogged
472 default:
473 trimmedOptions = append(trimmedOptions, opt)
474 }
475 }
476 default:
477 return NotYetSupportedError("ALTER TABLE variant is not yet supported")
478 }
479 trimmedOptions = append(trimmedOptions,
480 tree.SequenceOption{
481 Name: tree.SeqOptOwnedBy,
482 ColumnItemVal: tree.NewColumnItem(&tableName, node.Column),
483 },
484 tree.SequenceOption{
485 Name: tree.SeqOptViaAlterTable,
486 },
487 )
488 return nodeCreateSequence(ctx, &tree.CreateSequence{
489 IfNotExists: false,
490 Name: seqName,
491 Persistence: persistence,
492 Options: trimmedOptions,
493 })
494}

Callers 1

nodeAlterTableFunction · 0.85

Calls 3

NewColumnItemFunction · 0.92
NotYetSupportedErrorFunction · 0.85
nodeCreateSequenceFunction · 0.85

Tested by

no test coverage detected