How to add a default value for update in postgresql?

by ryan.murray , in category: MySQL , 6 months ago

How to add a default value for update in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 5 months ago

@ryan.murray 

In PostgreSQL, you can add a default value for a column when updating a table by using the ALTER TABLE statement with the ALTER COLUMN clause.


Here is an example of how you can add a default value for a column named "column_name" in a table named "table_name":

1
2
ALTER TABLE table_name
ALTER COLUMN column_name SET DEFAULT default_value;


Replace "table_name" with the name of your table, "column_name" with the name of the column you want to add the default value to, and "default_value" with the value you want to set as the default value.


After running this SQL statement, any new rows added to the table that do not specify a value for the column will use the default value you specified.