NAME
DBIO::DuckDB::Diff::Column - Diff operations for DuckDB columns
VERSION
version 0.900007
DESCRIPTION
Column-level diff operations for DuckDB. Unlike SQLite, DuckDB has a reasonably complete ALTER TABLE:
ALTER TABLE ... ADD COLUMNALTER TABLE ... DROP COLUMNALTER TABLE ... ALTER COLUMN ... SET DATA TYPEALTER TABLE ... ALTER COLUMN ... SET / DROP NOT NULLALTER TABLE ... ALTER COLUMN ... SET / DROP DEFAULT
ADD COLUMN takes a constant default only. A column that is NOT NULL, or has an expression default, is added in steps: the column, then SET DEFAULT and an UPDATE that gives the rows already there the default, then SET NOT NULL. A NOT NULL column without a default over a table that holds rows, and a column that becomes NOT NULL over NULLs, are refused by "_check_before_apply" in DBIO::DuckDB::Deploy before the first statement.
So actual type and nullability changes are emitted as real ALTER statements rather than commented-out warnings.
Brand-new tables get their columns inline via DBIO::DuckDB::Diff::Table -- this module only sees columns of tables that exist in both models.
ATTRIBUTES
lossless_pairs
my %pairs = %DBIO::DuckDB::Diff::Column::LOSSLESS_PAIRS;
The changes of data_type that DuckDB carries out without loss, as the old->new keys "column_change_lossy" in DBIO::Diff::Compare reads. Each pair was measured on libduckdb 1.5.3 (ALTER ... SET DATA TYPE over the boundary values of the old type, read back through a cast to it): the signed integers to a wider one (TINYINT < SMALLINT < INTEGER < BIGINT < HUGEINT), the unsigned ones to a wider one (UTINYINT to UBIGINT), an unsigned integer to a signed one of more bits, and DATE to TIMESTAMP (midnight). Every other pair is lossy, in doubt it is: a number to VARCHAR or JSON rewrites it, FLOAT to DOUBLE alters the decimal reading, an integer to DECIMAL fails when it does not fit, TIMESTAMP and TIMESTAMPTZ depend on the session's time zone, and anything from VARCHAR is parsed. DECIMAL(p,s) to DECIMAL(p2,s) with p2 at least p is lossless through the size comparison.
METHODS
diff
as_sql
early_sql
late_sql
as_sql in two parts. late_sql is the SET NOT NULL of a column that was added with an expression default: DuckDB cannot run it in the transaction that holds the UPDATE filling the rows ("Cannot create index with outstanding updates"). "_execute_diff" in DBIO::DuckDB::Deploy runs early_sql of every operation in one transaction and the late_sql parts after it. Empty for every other operation.
lossy
True for an alter that can alter or lose stored values, so that "apply" in DBIO::Deploy::Base runs it only with allow_destructive. The answer is "column_change_lossy" in DBIO::Diff::Compare over the types of the two columns with the pairs of "lossless_pairs"; the precision and scale of a DECIMAL(p,s) are read as its size. A change of NOT NULL and of the default keeps every value (NOT NULL over a NULL is refused by "_check_before_apply" in DBIO::DuckDB::Deploy). Other actions are not lossy.
summary
AUTHOR
DBIO Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.