
DROP FUNCTION IF EXISTS public.get_contracts();

CREATE OR REPLACE FUNCTION public.get_contracts()
RETURNS TABLE (
    Id               INTEGER,
    ContractorName   VARCHAR,
    ContractorSurname VARCHAR,
    ContractInitDate TIMESTAMP,
    RateName         VARCHAR
)
AS $$
    SELECT
        c.id,
        c.contractorname,
        c.contractorsurname,
        c.contractinitdate,
        r.name   AS RateName
    FROM public.contracts  AS c
    JOIN public.rates      AS r
      ON r.id = c.rateid
    ORDER BY c.id;
$$ LANGUAGE SQL STABLE;