merge into {comment_ban_table_name} as target
using (select $1:id as id, $1:reason as reason, $1:created_at as created_at, $1:updated_at as updated_at, $1:expires_at as expires_at, $1:banned_user_id as banned_user_id, $1:is_released as is_released, date(to_timestamp(created_at)) as p_date, hour(to_timestamp(created_at)) as p_hour from {stage_path} (file_format => 'BASIC_PARQUET_LOADER', pattern => ('.*.parquet'))) as source
on (target.id = source.id and target.p_date = source.p_date and target.p_hour = source.p_hour)
when matched then update set target.reason = source.reason, target.created_at = source.created_at, target.updated_at = source.updated_at, target.expires_at = source.expires_at, target.banned_user_id = source.banned_user_id, target.is_released = source.is_released
when not matched then insert (id, reason, created_at, updated_at, expires_at, banned_user_id, is_released, p_date, p_hour) values (source.id, source.reason, source.created_at, source.updated_at, source.expires_at, source.banned_user_id, source.is_released, source.p_date, source.p_hour);

