AddColumn implements sql.AlterableTable.
(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder)
| 221 | func setPrimaryKeyColumns(schema sql.Schema, ordinals []int) { |
| 222 | for _, idx := range ordinals { |
| 223 | schema[idx].PrimaryKey = true |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // String implements sql.Table. |
| 228 | func (t *Table) String() string { |
| 229 | return t.name |
| 230 | } |
| 231 | |
| 232 | // PrimaryKeySchema implements sql.PrimaryKeyTable. |
| 233 | func (t *Table) PrimaryKeySchema() sql.PrimaryKeySchema { |
| 234 | return t.schema |
| 235 | } |
| 236 | |
| 237 | func getPrimaryKeyOrdinals(ctx *sql.Context, catalogName, dbName, tableName string) []int { |
| 238 | rows, err := adapter.QueryCatalog(ctx, ` |
| 239 | SELECT constraint_column_indexes FROM duckdb_constraints() WHERE ((database_name = ? AND schema_name = ? AND table_name = ?) OR (database_name = 'temp' AND schema_name = 'main' AND table_name = ?)) AND constraint_type = 'PRIMARY KEY' LIMIT 1 |
| 240 | `, catalogName, dbName, tableName, tableName) |
| 241 | if err != nil { |
| 242 | panic(ErrDuckDB.New(err)) |
| 243 | } |
| 244 | defer rows.Close() |
| 245 | |
| 246 | var ordinals []int |
| 247 | if rows.Next() { |
| 248 | var arr duckdb.Composite[[]int] |
| 249 | if err := rows.Scan(&arr); err != nil { |
| 250 | panic(ErrDuckDB.New(err)) |
| 251 | } |
| 252 | ordinals = arr.Get() |
| 253 | } |
| 254 | if err := rows.Err(); err != nil { |
| 255 | panic(ErrDuckDB.New(err)) |
| 256 | } |
| 257 | return ordinals |
| 258 | } |
| 259 | |
| 260 | func getCreateSequence(temporary bool, sequenceName string) (createStmt, fullName string) { |
| 261 | if temporary { |
| 262 | return `CREATE TEMP SEQUENCE "` + sequenceName + `"`, `temp.main."` + sequenceName + `"` |
| 263 | } |
| 264 | fullName = InternalSchemas.SYS.Schema + `."` + sequenceName + `"` |
| 265 | return `CREATE SEQUENCE ` + fullName, fullName |
| 266 | } |
| 267 | |
| 268 | // AddColumn implements sql.AlterableTable. |
| 269 | func (t *Table) AddColumn(ctx *sql.Context, column *sql.Column, order *sql.ColumnOrder) error { |
| 270 | t.mu.Lock() |
| 271 | defer t.mu.Unlock() |
| 272 | |
| 273 | // TODO: Column order is ignored as DuckDB does not support it. |
| 274 | |
| 275 | typ, err := DuckdbDataType(column.Type) |
| 276 | if err != nil { |
| 277 | return err |
| 278 | } |
| 279 | |
| 280 | var sqls []string |
nothing calls this directly
no test coverage detected