I have a dates tables, columns:
- date: the date e.g. '2018-06-29'
- business_day: 1 or 0 to indicate if date is business day or not
I want to create a User-Defined function in Redshift that outputs between two dates how many business days. In a select statement is will look like :
select business_days(start_date timestamp, end_date timestamp) as integer
for example:
2018-06-29 is a friday business day
2018-06-30 saturday non business day
2018-07-01 sunday non business day
2018-07-02 business day
select business_days( '2018-06-29', '2018-07-02')
should output 2
Redshift does not allow aggregates inside a function and I am looking for a workaround.