DROP FUNCTION IF EXISTS public.check_rate_exists(INTEGER);

CREATE OR REPLACE FUNCTION public.check_rate_exists(p_id INTEGER)
RETURNS INTEGER
AS $$
    SELECT CASE
             WHEN EXISTS (
                    SELECT 1
                      FROM public.rates
                     WHERE id = p_id
                 )
             THEN 1
             ELSE 0
           END;
$$ LANGUAGE SQL STABLE;
