pgsql function 샘플
CREATE OR REPLACE FUNCTION public.fn_days_ago(today varchar,ago numeric)
RETURNS varchar
LANGUAGE plpgsql
STABLE PARALLEL SAFE
AS
$function$
BEGIN
IF ago = 0 THEN
RETURN today;
ELSE
RETURN min(stock_date) AS stock_date FROM (
SELECT stock_date
FROM stock_day_chart sdc
WHERE stock_cd ='000660'
AND stock_date < today ORDER BY stock_date DESC LIMIT ago
) a;
END IF;
END;
$function$
;
728x90
댓글