0

I have two datasets but need a function that can read any table (by adding the table name in the parameter??) One data set (order) contains order ID's and the purchasetime, the second one (payment) contains the order ID, payment type and purchasetime. this is what i have tried so far

create function sales_per_day(Table_name  text, first_day timestamp,last_day  timestamp)
returns int
language plpgsql
as
$$
declare
   sales_count integer;
begin
   select count(*) 
   into sales_count
   from Table_name
   where inserted_at BETWEEN first_day AND last_day;
   
   return sales_count;
end;
$$;

when i type out

select * FROM sales_per_day('orders', '2019-08-05', '2019-08-10') 

I would love to see the number of sales done between those two days. but it doesn't recognize the table name

0 Answers0