I have to write a PL/pgSQL stored procedure which has two inputs.
The first input should go into a select which returns a set of timestamps.
With these returned timestamps I intend to loop over a second select, which takes the second input of the function and returns a single row I have to collect in the iteration of the loop. I then assemble the output of the second select and return that as a result set.
FUNCTION (Input A B)
SELECT FROM T1 WHERE X = A INTO RS1.
LOOP VAL OVER RS1
Select FROM T2 WHERE Y = B AND Z = VAL INTO RS2
END LOOP
RETURN ASSEMBLED RS2
Can somebody point me to a working skeleton on which I can work on, btw. what are the relevant parts I need from the documentation? I think I need:
RETURNS TABLE () AS
to declare the result setA
CURSOR
to loop over the second query, using the results of the first query
join
? – Gordon Linoff Jan 30 at 14:38JOIN
is not really related toIN
-- you can read more about the concept here – pozs Jan 30 at 15:21