I got this sproc where i get the volume depending on a "FlowVolume" it could be 1, 10, 100. The only way that I found to make this work is the current implementation, but is really slow. The other way is to have intervals in the "Timestamp" it could be every 12 seconds, every 2 mins or every 20 mins intervals.
CREATE OR REPLACE FUNCTION "getBLTPoints"(IN id integer)
RETURNS TABLE(times text, bio text, particles text) AS
$BODY$
DECLARE
currVol real;
currbio integer;
currpart integer;
times timestamp with time zone;
totalvol integer;
profileid integer;
analysisopt integer;
analysisvol integer;
counter integer;
BEGIN
--Getting the right profile to get the line,autosample,analysis volume
select "ProfileID"into profileid from "Samples" where "ID" = id;
--Getting the mode that the system was in when sample was done
select "optBaseVolume" into analysisopt from "Profiles" where "ID" = profileid;
if(analysisopt = 0) then
analysisvol = 1;
elseif(analysisopt = 1) then
analysisvol = 10;
else
analysisvol = 100;
end if;
counter = analysisvol;
--Getting the totalvolume to run it in the while loop until it reaches the totalvolume
select floor("FlowVolume")::integer into totalvol from "Results" where "SampleID" = id order by "FlowVolume" desc limit 1;
WHILE counter <= totalvol LOOP
RETURN QUERY
select extract('epoch' from "Timestamp")::text,"BioAccumulated"::text, "TotalParticlesAccum"::text from
"Results" where "SampleID" = id and "FlowVolume" = counter;
counter = counter + analysisvol;
END LOOP;
END;