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

Function nodeAlterTable

server/ast/alter_table.go:30–81  ·  view source on GitHub ↗

nodeAlterTable handles *tree.AlterTable nodes.

(ctx *Context, node *tree.AlterTable)

Source from the content-addressed store, hash-verified

28
29// nodeAlterTable handles *tree.AlterTable nodes.
30func nodeAlterTable(ctx *Context, node *tree.AlterTable) (vitess.Statement, error) {
31 if node == nil {
32 return nil, nil
33 }
34
35 treeTableName := node.Table.ToTableName()
36 tableName, err := nodeTableName(ctx, &treeTableName)
37 if err != nil {
38 return nil, err
39 }
40
41 // We don't implement sequence addition/modification as a DDL since it's not in GMS, so we only support one of these
42 // at a time. If there are more than one, then we'll return an error in the command loop.
43 if len(node.Cmds) == 1 {
44 cmd, ok := node.Cmds[0].(*tree.AlterTableComputed)
45 if ok {
46 return nodeAlterTableComputed(ctx, treeTableName, cmd)
47 }
48 if vcmd, ok := node.Cmds[0].(*tree.AlterTableValidateConstraint); ok {
49 return vitess.InjectedStatement{
50 Statement: pgnodes.NewValidateConstraint(
51 tableName.SchemaQualifier.String(),
52 tableName.Name.String(),
53 bareIdentifier(vcmd.Constraint),
54 ),
55 Children: nil,
56 }, nil
57 }
58 }
59 statements, noOps, err := nodeAlterTableCmds(ctx, node.Cmds, tableName, node.IfExists)
60 if err != nil {
61 return nil, err
62 }
63
64 // If there are no valid statements return a no-op statement
65 if len(noOps) > 0 && len(statements) == 0 {
66 return NewNoOp(noOps...), nil
67 }
68
69 // Otherwise emit warnings now, then return an AlterTable statement
70 // TODO: we don't have a way to send or store the warnings alongside a valid AlterTable statement. We could either
71 // get a *sql.Context here and emit warnings, or we could store the warnings in the Context and make the caller
72 // emit them before it sends |ReadyForQuery|
73 // if len(noOps) > 0 {
74 // emit warnings
75 // }
76
77 return &vitess.AlterTable{
78 Table: tableName,
79 Statements: statements,
80 }, nil
81}
82
83// nodeAlterTableSetSchema handles *tree.AlterTableSetSchema nodes.
84func nodeAlterTableSetSchema(ctx *Context, node *tree.AlterTableSetSchema) (vitess.Statement, error) {

Callers 1

ConvertFunction · 0.85

Calls 7

nodeTableNameFunction · 0.85
nodeAlterTableComputedFunction · 0.85
bareIdentifierFunction · 0.85
nodeAlterTableCmdsFunction · 0.85
NewNoOpFunction · 0.85
ToTableNameMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected