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

From Jim Nasby
Subject Re: function returning a merge of the same query executed X time
Date
Msg-id 5537BC65.1070106@BlueTreble.com
Whole thread Raw
In response to function returning a merge of the same query executed X time  (Marc-André Goderre <magoderre@cgq.qc.ca>)
List pgsql-general
On 4/22/15 8:14 AM, Marc-André Goderre wrote:
>      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

Untested...

CREATE FUNCTION ...(
   ...
   , iterations int
)
LANGUAGE sql AS
$body$
     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
        , generate_series(1, iterations) i
$body$
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


pgsql-general by date:

Previous
From: Marc-André Goderre
Date:
Subject: function returning a merge of the same query executed X time
Next
From: Geoff Winkless
Date:
Subject: Re: function returning a merge of the same query executed X time