Search Postgresql Archives

Re: A function which returns all rolname from pg_roles.

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

 



Karen Hill wrote:
How do I make this function work?  I am trying to get all the rolnames
from pg_roles.


Why not just do "SELECT rolname FROM pg_roles;"?

Anyway, in PL/pgSQL:

CREATE OR REPLACE FUNCTION test() RETURNS SETOF name AS $$
  DECLARE
    rec  record;
  BEGIN
    FOR rec IN SELECT rolname FROM pg_roles LOOP
      RETURN NEXT rec.rolname;
    END LOOP;
  END;
$$ LANGUAGE plpgsql;

And simpler as an SQL function (although, again, why bother?):

CREATE OR REPLACE FUNCTION test_sql() RETURNS SETOF name AS $$
    SELECT rolname FROM pg_roles
$$ LANGUAGE sql;

HTH,

Joe


[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