Here's a function that provides a result of 2 columns.
In this function there's a Loop been used to return the result.
Function :
Create Type Repeat_rs as (
label text,
count bigint
)
CREATE OR REPLACE FUNCTION Repeat(fromDate date,toDate date)
returns SETOF Repeat_rs
AS
$$
Declare someVariableName Repeat_rs;
BEGIN
For someVariableName in (
SELECT label, count(*) AS Cnt from test where date between fromDate and toDate group by circle
) Loop
Return Next someVariableName;
End Loop;
Return;
END;
$$
LANGUAGE plpgsql;
Is there any possibilities of returning the rows without using loop?
If so please do share me on how we can do it.
And will I be able to write a function to insert records on to a table without using loop?
Help me out to solve this query.
Thanks in advance.
circle, but uselabelas a selected column. postgresql.org/docs/9.3/static/sql-select.html#SQL-GROUPBYgroupby.