Search
 
SCRIPT & CODE EXAMPLE
 

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$
;
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql loop 
Sql :: to_char oracle 
Sql :: sqlite3 update select 
Sql :: postgres role does not exist 
Sql :: sql update multiple columns 
Sql :: mysql regex exact match 
Sql :: SQL COUNT() with WHERE 
Sql :: insert array into mysql column 
Sql :: full join sql 
Sql :: sql where part of string match 
Sql :: sql run multiple updates in one query 
Sql :: how to get previous year from sysdate in oracle 
Sql :: grant all privileges database postgres to user 
Sql :: coalesce sql 
Sql :: sqlalchemy get schema from database 
Sql :: array of objects sql 
Sql :: identify primary key in oracle table 
Sql :: select only the month-day from date in PL-SQL 
Sql :: sub query postgres 
Sql :: between 
Sql :: oracle error line 
Sql :: import mysql database command line 
Sql :: delete table row in postgresql 
Sql :: new uniqueidentifier in sql 
Sql :: insert many to many sql 
Sql :: relation does not exist postgresql 
Sql :: Create the connection pool mysql2 
Sql :: mysql decimal remove trailing zeros 
Sql :: Drop check constraint in ms sql 
Sql :: having in sql server 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =