Search Postgresql Archives

Help with function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I need some help with writing a plpgsql function.  I want to return multiple items from the function.  How do I do this?

Here is my attempt at the function (note, this is a simple example that could obviously be done via a view, but I am trying to learn more about writing plpgsql functions):

create or replace function dba.active_transactions_by_db() returns setof integer pg_stat_activity.datname%TYPE as
$BODY$
declare
    dbName            varchar;
    activeTransactions    integer;
    countRec        record;
begin
    for countRec in select count(1) as cnt, datname from pg_stat_activity group by datname loop
        return next countRec;
    end loop;
   
    return countRec;
end;
$BODY$
language plpgsql;

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux