VARCHAR(n) Length Compatibility Boundary When Migrating to DuckDB
0 reputation · 23 Jun 2024, 13:38 UTC
VARCHAR(n) Length Compatibility Boundary When Migrating to DuckDB
Goal: Preserve declared VARCHAR(n) maximums as database-enforced limits when porting a schema from PostgreSQL or MySQL into DuckDB.
DuckDB treats VARCHAR(n), VARCHAR, and TEXT as synonymous unbounded string types. The optional n is not enforced during INSERT or CAST, and PRIMARY KEY, UNIQUE, or CHECK constraints do not imply a length cap. This creates a compatibility boundary for applications that assume the storage layer rejects values longer than n.
Whether DuckDB offers any session or database setting to enable length enforcement, and whether an explicit CHECK constraint is the only reliable way to enforce application-level length limits, remains an open design question.
Does DuckDB enforce VARCHAR(n) length in any release or configuration mode? Can length enforcement be enabled globally or per database? What schema pattern preserves VARCHAR(n) semantics when migrating from strict-length databases?