nodeCreateSequence handles *tree.CreateSequence nodes.
(ctx *Context, node *tree.CreateSequence)
| 30 | |
| 31 | // nodeCreateSequence handles *tree.CreateSequence nodes. |
| 32 | func nodeCreateSequence(ctx *Context, node *tree.CreateSequence) (vitess.Statement, error) { |
| 33 | if node == nil { |
| 34 | return nil, nil |
| 35 | } |
| 36 | if node.Persistence.IsTemporary() { |
| 37 | return nil, errors.Errorf("temporary sequences are not yet supported") |
| 38 | } |
| 39 | if node.Persistence.IsUnlogged() { |
| 40 | return nil, errors.Errorf("unlogged sequences are not yet supported") |
| 41 | } |
| 42 | name, err := nodeTableName(ctx, &node.Name) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | if len(name.DbQualifier.String()) > 0 { |
| 47 | return nil, errors.Errorf("CREATE SEQUENCE is currently only supported for the current database") |
| 48 | } |
| 49 | // Read all options and check whether they've been set (if not, we'll use the defaults) |
| 50 | minValueLimit := int64(math.MinInt64) |
| 51 | maxValueLimit := int64(math.MaxInt64) |
| 52 | increment := int64(1) |
| 53 | var minValue int64 |
| 54 | var maxValue int64 |
| 55 | var start int64 |
| 56 | var dataType *pgtypes.DoltgresType |
| 57 | var ownerTableName string |
| 58 | var ownerColumnName string |
| 59 | minValueSet := false |
| 60 | maxValueSet := false |
| 61 | incrementSet := false |
| 62 | startSet := false |
| 63 | cycle := false |
| 64 | fromAlter := false |
| 65 | for _, option := range node.Options { |
| 66 | switch option.Name { |
| 67 | case tree.SeqOptAs: |
| 68 | if !dataType.IsEmptyType() { |
| 69 | return nil, errors.Errorf("conflicting or redundant options") |
| 70 | } |
| 71 | _, dataType, err = nodeResolvableTypeReference(ctx, option.AsType, false) |
| 72 | if err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | switch dataType.ID { |
| 76 | case pgtypes.Int16.ID: |
| 77 | minValueLimit = int64(math.MinInt16) |
| 78 | maxValueLimit = int64(math.MaxInt16) |
| 79 | case pgtypes.Int32.ID: |
| 80 | minValueLimit = int64(math.MinInt32) |
| 81 | maxValueLimit = int64(math.MaxInt32) |
| 82 | case pgtypes.Int64.ID: |
| 83 | minValueLimit = int64(math.MinInt64) |
| 84 | maxValueLimit = int64(math.MaxInt64) |
| 85 | default: |
| 86 | return nil, errors.Errorf("sequence type must be smallint, integer, or bigint") |
| 87 | } |
| 88 | case tree.SeqOptCycle: |
| 89 | cycle = true |
no test coverage detected