-- Check if the function exists and show all overloaded versions
SELECT
    proname as function_name,
    pg_get_function_arguments(oid) as arguments,
    pg_get_functiondef(oid) as definition
FROM pg_proc
WHERE pronamespace = 'public'::regnamespace
  AND proname = 'rpc_analytics_user_kpis'
ORDER BY oid;

-- Alternative: Check function existence with more details
SELECT
    n.nspname as schema_name,
    p.proname as function_name,
    pg_get_function_arguments(p.oid) as arguments,
    pg_get_function_result(p.oid) as return_type,
    p.prokind as function_type,
    CASE p.prokind
        WHEN 'f' THEN 'Function'
        WHEN 'p' THEN 'Procedure'
        WHEN 'a' THEN 'Aggregate'
        WHEN 'w' THEN 'Window'
    END as kind
FROM pg_proc p
JOIN pg_namespace n ON p.pronamespace = n.oid
WHERE p.proname = 'rpc_analytics_user_kpis'
  AND n.nspname = 'public'
ORDER BY p.oid;

-- Check all functions in public schema
SELECT
    proname as function_name,
    pg_get_function_arguments(oid) as arguments
FROM pg_proc
WHERE pronamespace = 'public'::regnamespace
ORDER BY proname;

-- Quick existence check
SELECT
    EXISTS(
        SELECT 1
        FROM pg_proc
        WHERE pronamespace = 'public'::regnamespace
          AND proname = 'rpc_analytics_user_kpis'
    ) as function_exists;