I have a function called generate_table, that takes 2 input parameters (rundate::date
and branch::varchar
)
Now I am trying to work on a second function, using PLPGSQL, that will get a list of all branches and the newest date for each branch and pass this as a parameter to the generate_table function.
The query that I have is this:
select max(rundate) as rundate, branch
from t_index_of_imported_files
group by branch
and it results on this:
rundate;branch
2014-03-13;branch1
2014-03-12;branch2
2014-03-10;branch3
2014-03-13;branch4
and what I need is that the function run something like this
select generate_table('2014-03-13';'branch1');
select generate_table('2014-03-12';'branch2');
select generate_table('2014-03-10';'branch3');
select generate_table('2014-03-13';'branch4');
I've been reading a lot about PLPGSQL but so far I can only say that I barely know the basics.
I read that one could use a concatenation in order to get all the values together and then use a EXECUTE within the function, but I couldn't make it work properly.
Any suggestions on how to do this?