Changes a column's type in place with ALTER TABLE ... ALTER COLUMN ... SET TYPE. DuckLake permits widening promotions only (for example
INTEGER to BIGINT, or FLOAT to DOUBLE): every existing value
must be representable in the new type, so no data can be lost and no
data files need rewriting.
Details
To narrow a type, which DuckLake refuses, take the explicit route:
add_table_column() with the smaller type, copy the values over (after
checking they fit), drop_table_column() the original, and
rename_table_column() the new column into place.
Examples
lake_dir <- tempfile("coltype_lake_")
dir.create(lake_dir)
attach_ducklake("coltype_lake", lake_path = lake_dir)
create_table(mtcars, "cars")
# Widening promotions only: INTEGER -> BIGINT is fine
add_table_column("cars", "order_id", "INTEGER")
#> Added column "order_id" (INTEGER) to "cars".
#> ℹ Metadata-only change; no data files were rewritten.
set_column_type("cars", "order_id", "BIGINT")
#> Column "order_id" in "cars" is now BIGINT.
detach_ducklake("coltype_lake", shutdown = TRUE)
unlink(lake_dir, recursive = TRUE)
