nodeAlterTableComputed converts a tree.AlterTableComputed instance into an equivalent CREATE/ALTER SEQUENCE statement.
(ctx *Context, tableName tree.TableName, node *tree.AlterTableComputed)
| 445 | |
| 446 | // nodeAlterTableComputed converts a tree.AlterTableComputed instance into an equivalent CREATE/ALTER SEQUENCE statement. |
| 447 | func 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 | } |
no test coverage detected