Re: A function which returns all rolname from pg_roles.

From: Joe Conway <mail(at)joeconway(dot)com>
To: Karen Hill <karen_hill22(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: A function which returns all rolname from pg_roles.
Date: 2006-07-11 04:57:02
Message-ID: 44B32F9E.2000802@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2006-07-11 05:09:45 Re: A function which returns all rolname from pg_roles.
Previous Message Tom Lane 2006-07-11 03:46:49 Re: US Telephone Number Type