function returning a merge of the same query executed X time - Mailing list pgsql-general

From Marc-André Goderre
Subject function returning a merge of the same query executed X time
Date
Msg-id D8DAC91BA6256246BA3FF835F6AAA1189943EC2B@SI-MB01.cegep-chicoutimi.qc.ca
Whole thread Raw
Responses Re: function returning a merge of the same query executed X time
Re: function returning a merge of the same query executed X time
Re: function returning a merge of the same query executed X time
List pgsql-general
Hi all,
I'm having difficulties to  create a function that should execute X time the same query and return  their results as a
singletable. 
I tried this way but it don't work :
Thanks to help.

create function cm_get_json_loop_info(
    IN profile integer,
    IN distance double precision DEFAULT 10,
    IN x_start double precision DEFAULT 0,
    IN y_start double precision DEFAULT 0,
    IN nbr integer default 1)

    returns setof json as
    $BODY$
    declare jsona json;
    BEGIN
    for json a i in 1.. nbr loop

    select row_to_json(q)
    from (select row_number() over() as id, sum(cost) as total_cost,sum(length) as
total_length,json_agg(row_to_json(r))as data  
        from (select * from cm_get_loop_route_4(2, 10, -73.597070, 45.544083))r)q
     return next jsona
    end loop;
    return jsona;

Marc



pgsql-general by date:

Previous
From: Keith Fiske
Date:
Subject: Re: Background worker assistance & review
Next
From: Jim Nasby
Date:
Subject: Re: function returning a merge of the same query executed X time