MERGE INTO {ddb_clip_meta_heavy_table_name} AS target
USING
(
    SELECT
        $1:Keys:clipId:S AS id,
        $1:NewImage:prompt:S AS prompt,
        $1:NewImage:prompt_text:S AS prompt_text,
        '{p_date}'::DATE AS p_date,
        {p_hour} AS p_hour
    FROM {stage_path} (file_format => 'BASIC_JSON_LOADER', pattern => ('.*'))
) AS source
ON (target.id = source.id)
WHEN MATCHED THEN
    UPDATE SET
        target.prompt = source.prompt,
        target.prompt_text = source.prompt_text,
        target.p_date = source.p_date,
        target.p_hour = source.p_hour
WHEN NOT MATCHED THEN
    INSERT (id, prompt, prompt_text, p_date, p_hour)
    VALUES (source.id, source.prompt, source.prompt_text, source.p_date, source.p_hour);

