I'm merging data from one table into another in Spark/Databricks. I can do and update set * if all columns are selected but this fails if all columns are not selected (e.g. if there is a col9 in the dst table in the query below). Is there a way to do this merge without repeating the long list of columns in the when matched (i.e. match by column name in the source query) and when not matched segments?
merge into demo dst
using (
select distinct
col1,
col2,
col3,
col4,
col5,
col6,
col7,
col8
from
demo_raw
where 1=1
and col1 = 'ac'
and col2 is not null
) src
on src.col1 = dst.col1
when matched then
update set *
when not matched then
insert *
;