database - PostgreSQL - Function to return multiple columns -


here's function provides result of 2 columns.

in function there's loop been used return result.

function :

 create type repeat_rs ( label text, count bigint )  create or replace function repeat(fromdate date,todate date) returns setof  repeat_rs  $$ declare somevariablename repeat_rs; begin     somevariablename in (         select label, count(*) cnt test date between fromdate , todate group circle     ) loop     return next somevariablename;     end loop;     return; end; $$ language plpgsql; 

is there possibilities of returning rows without using loop?

if please share me on how can it.

and able write function insert records on table without using loop?

help me out solve query.

thanks in advance.

you don't need type definition. , return multiple rows, use return query:

something this:

create or replace function repeat(fromdate date,todate date)   returns table (label text, cnt bigint)  $$ begin     return query         select label, count(*) cnt         test         date between fromdate , todate        group label; end; $$ language plpgsql; 

you don't need pl/pgsql function, can use simple sql function this:

create or replace function repeat(fromdate date, todate date)   returns table (label text, cnt bigint)  $$    select label, count(*) cnt     test     date between fromdate , todate    group label; $$ language sql; 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -