DropColumn implements sql.AlterableTable.
(ctx *sql.Context, columnName string)
| 309 | } |
| 310 | sql += " DEFAULT " + defaultExpr |
| 311 | } else if column.AutoIncrement { |
| 312 | typ.mysql.AutoIncrement = true |
| 313 | |
| 314 | // Generate a random sequence name. |
| 315 | uuid, err := uuid.NewRandom() |
| 316 | if err != nil { |
| 317 | return err |
| 318 | } |
| 319 | sequenceName = SequenceNamePrefix + uuid.String() |
| 320 | createSequenceStmt, fullSequenceName = getCreateSequence(temporary, sequenceName) |
| 321 | sqls = append(sqls, createSequenceStmt) |
| 322 | |
| 323 | defaultExpr := `nextval('` + fullSequenceName + `')` |
| 324 | sql += " DEFAULT " + defaultExpr |
| 325 | } |
| 326 | |
| 327 | sqls = append(sqls, sql) |
| 328 | |
| 329 | // DuckDB does not support constraints in ALTER TABLE ADD COLUMN statement, |
| 330 | // so we need to add NOT NULL constraint separately. |
| 331 | // > Parser Error: Adding columns with constraints not yet supported |
| 332 | if !column.Nullable { |
| 333 | sqls = append(sqls, `ALTER TABLE `+FullTableName(t.db.catalog, t.db.name, t.name)+` ALTER COLUMN `+QuoteIdentifierANSI(column.Name)+` SET NOT NULL`) |
| 334 | } |
| 335 | |
| 336 | // Add column comment |
| 337 | comment := NewCommentWithMeta(column.Comment, typ.mysql) |
| 338 | sqls = append(sqls, `COMMENT ON COLUMN `+FullColumnName(t.db.catalog, t.db.name, t.name, column.Name)+` IS '`+comment.Encode()+`'`) |
| 339 | |
| 340 | // Add table comment if it is AUTO_INCREMENT or PRIMARY KEY |
| 341 | tableInfo := t.comment.Meta |
| 342 | tableInfoChanged := false |
| 343 | if column.AutoIncrement { |
| 344 | tableInfo.Sequence = fullSequenceName |
| 345 | tableInfoChanged = true |
| 346 | } |
| 347 | if column.PrimaryKey { |
| 348 | sqls = append(sqls, `ALTER TABLE `+FullTableName(t.db.catalog, t.db.name, t.name)+` ADD PRIMARY KEY (`+QuoteIdentifierANSI(column.Name)+`)`) |
| 349 | tableInfo.PkOrdinals = []int{len(t.schema.Schema)} |
nothing calls this directly
no test coverage detected