-- Merge geo information (country, city) into WEB_AUDIO_PLAYER_ACTIONS table
-- This updates the COUNTRY and CITY fields based on CLIENT_IP using a temporary geo table
MERGE INTO {web_audio_player_actions_table_name} AS target
USING (
    SELECT "ip" AS ip, "country" AS country, "city" AS city 
    FROM IDENTIFIER('{geo_table_name}')
) AS source
ON (target.client_ip = source.ip AND target.p_date = '{p_date}' AND target.p_hour = {p_hour})
WHEN MATCHED THEN
    UPDATE SET 
        target.country = source.country,
        target.city = source.city;

