RefLib

Reference library for AI

Back

postgresql_16:3.2.6.5 Changing a Column's Default Value

PostgreSQL 16 > The SQL Language > Data Definition > Modifying Tables > Changing a Column's Default Value

To set a new default for a column, use a command like: ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77; Note that this doesn't affect any existing rows in the table, it just changes the default for future INSERT commands.

To remove any default value, use: ALTER TABLE products ALTER COLUMN price DROP DEFAULT; This is effectively the same as setting the default to null. As a consequence, it is not an error to drop a default where one hadn't been defined, because the default is implicitly the null value.

Back