I would like to copy data from one table into another, but the source table may have nulls in columns where the destination table does not allow nulls but has default values:
drop table if exists table_with_nulls;
create table table_with_nulls
(
value1 integer,
value2 integer
);
insert into table_with_nulls values (1, null);
drop table if exists table_with_defaults;
create table table_with_defaults
(
value1 integer not null default 10,
value2 integer not null default 20
);
insert into table_with_defaults (value1, value2)
select value1, value2 from table_with_nulls;
That throws an exception due to the null value from table_with_nulls.value2. Is there a reasonably easy way to get a value of 20 for table_with_defaults.value2?