I have PostgreSQL table with several boolean columns, currently containing only true or null. I want to do the following for all of them:
- Add a default value of
false - Change all
nullvalues tofalse - Add a
not nullconstraint
ie.:
-- for each column specified:
update my_table set my_column = 'f' where my_column is null;
alter table my_table alter column my_column set default 'f';
alter table my_table alter column my_column set not null;
Is there a feature of psql (or standard SQL) that will iterate over a specified list of columns and apply a sequence of operations to each one?