How can I add a DEFAULT value in DuckDB depending on another VARCHAR column?
- User
How can I add a DEFAULT value in DuckDB depending on another VARCHAR column?
Assistant
To add a DEFAULT value in DuckDB that depends on another VARCHAR column, the best approach is to use a GENERATED column. Here's how you can do it:
sqlCREATE TABLE example_table ( id INTEGER, category VARCHAR, description VARCHAR GENERATED ALWAYS AS ( CASE WHEN category = 'Electronics' THEN 'Electronic devices and accessories' WHEN category = 'Clothing' THEN 'Apparel and fashion items' ELSE 'Miscellaneous products' END ) STORED );Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.