merge into {contest_table_name} as target
using (select $1:id as id, $1:created_at as created_at, $1:updated_at as updated_at, $1:name as name, $1:type as type, $1:description as description, $1:start_time as start_time, $1:end_time as end_time, $1:submissions_playlist_id as submissions_playlist_id, $1:can_download_remixes as can_download_remixes, $1:image_s3_id as image_s3_id, date(to_timestamp(created_at)) as p_date from {stage_path} (file_format => 'BASIC_PARQUET_LOADER', pattern => ('.*.parquet'))) as source
on (target.id = source.id and target.p_date = source.p_date)
when matched then update set target.created_at = source.created_at, target.updated_at = source.updated_at, target.name = source.name, target.type = source.type, target.description = source.description, target.start_time = source.start_time, target.end_time = source.end_time, target.submissions_playlist_id = source.submissions_playlist_id, target.can_download_remixes = source.can_download_remixes, target.image_s3_id = source.image_s3_id
when not matched then insert (id, created_at, updated_at, name, type, description, start_time, end_time, submissions_playlist_id, can_download_remixes, image_s3_id, p_date) values (source.id, source.created_at, source.updated_at, source.name, source.type, source.description, source.start_time, source.end_time, source.submissions_playlist_id, source.can_download_remixes, source.image_s3_id, source.p_date);

