Search code examples
javasqljooq

JOOQ how to add column with default value into an existing table


The below DSL can add new column with nullable to existing table, but i don't know how to add a default value in this DSL.

DSL.using(dialect).alterTable(table("tableName"))
                    .add(field(name("newColName"),VARCHAR(32).nullable(false)))

Solution

  • It works the same way as nullable(), directly on the type. Use

    VARCHAR(32).nullable(false).default_("abc")