Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

postgres recursive function

CREATE OR REPLACE FUNCTION set_fun_compairecalender(_start_date timestamp without time zone DEFAULT now(), _company integer DEFAULT 2, _country integer DEFAULT 1)
 RETURNS timestamp without time zone
 LANGUAGE plpgsql
AS $function$
declare 
	dte timestamp;
begin
	
  select coalesce(hcl_date,'1900-01-01') into dte from holiday_calender hc where  hc.hcl_country = _country  and 
  hc.hcl_company  = _company  and hc.hcl_date::date = _start_Date::date;
	
  if coalesce(dte,'1900-01-01') <> '1900-01-01' then 
    -- Recursive function call at here
    select set_fun_compaireCalender into dte from set_fun_compaireCalender(dte::date + (' 1 day')::interval,_company,     _country);

  end if;

  return coalesce(dte,_start_Date)::date;

end
$function$
;
Source by itestee.com #
 
PREVIOUS NEXT
Tagged: #postgres #recursive #function
ADD COMMENT
Topic
Name
1+7 =