merge into {user_recent_subscription_table_name} as target
using (select $1:id as id, $1:user_id as user_id, $1:amount_paid as amount_paid, $1:currency as currency, $1:payment_method_type as payment_method_type, $1:created_at as created_at, $1:updated_at as updated_at, 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.user_id = source.user_id, target.amount_paid = source.amount_paid, target.currency = source.currency, target.payment_method_type = source.payment_method_type, target.created_at = source.created_at, target.updated_at = source.updated_at
when not matched then insert (id, user_id, amount_paid, currency, payment_method_type, created_at, updated_at, p_date, p_hour) values (source.id, source.user_id, source.amount_paid, source.currency, source.payment_method_type, source.created_at, source.updated_at, source.p_date, source.p_hour);

