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

Function nodeAlterSequence

server/ast/alter_sequence.go:29–102  ·  view source on GitHub ↗

nodeAlterSequence handles *tree.AlterSequence nodes.

(ctx *Context, node *tree.AlterSequence)

Source from the content-addressed store, hash-verified

27
28// nodeAlterSequence handles *tree.AlterSequence nodes.
29func nodeAlterSequence(ctx *Context, node *tree.AlterSequence) (vitess.Statement, error) {
30 if node == nil {
31 return nil, nil
32 }
33
34 var warnings []string
35 if len(node.Owner) > 0 {
36 // We intentionally don't support OWNER TO since we don't support owning objects
37 if len(node.Options) == 0 {
38 return NewNoOp("OWNER TO is unsupported and ignored"), nil
39 } else {
40 warnings = append(warnings, "OWNER TO is unsupported and ignored")
41 }
42 }
43 if node.SetLog {
44 return NotYetSupportedError("LOGGED and UNLOGGED are not yet supported")
45 }
46
47 nodeName := node.Name.ToTableName()
48 name, err := nodeTableName(ctx, &nodeName)
49 if err != nil {
50 return nil, err
51 }
52 if len(name.DbQualifier.String()) > 0 {
53 return NotYetSupportedError("ALTER SEQUENCE does not yet support specifying the database")
54 }
55
56 ownedBy := pgnodes.AlterSequenceOwnedBy{}
57 for _, option := range node.Options {
58 switch option.Name {
59 case tree.SeqOptOwnedBy:
60 ownedBy.IsSet = true
61 // OWNED BY NONE is valid, so we have to check if a column was provided
62 if option.ColumnItemVal != nil {
63 expr, err := nodeExpr(ctx, option.ColumnItemVal)
64 if err != nil {
65 return nil, err
66 }
67 colName, ok := expr.(*vitess.ColName)
68 if !ok {
69 return nil, errors.New("expected sequence owner to be a table and column name")
70 }
71 if colName.Qualifier.SchemaQualifier.String() != name.SchemaQualifier.String() {
72 return nil, errors.New("ALTER SEQUENCE must use the same schema for the sequence and owned table")
73 }
74 if len(colName.Qualifier.DbQualifier.String()) > 0 {
75 return nil, errors.New("database specification is not yet supported for sequences")
76 }
77 if len(colName.Name.String()) == 0 || len(colName.Qualifier.Name.String()) == 0 {
78 return nil, errors.New("invalid OWNED BY option")
79 }
80 ownedBy.Table = colName.Qualifier.Name.String()
81 ownedBy.Column = colName.Name.String()
82 }
83 default:
84 return NotYetSupportedError(fmt.Sprintf("%s is not yet supported", option.Name))
85 }
86 }

Callers 1

ConvertFunction · 0.85

Calls 6

NewNoOpFunction · 0.85
NotYetSupportedErrorFunction · 0.85
nodeTableNameFunction · 0.85
nodeExprFunction · 0.85
ToTableNameMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected