Handy user/group hack

From: David Fetter <david(at)fetter(dot)org>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Handy user/group hack
Date: 2003-11-21 04:09:27
Message-ID: 20031121040927.GJ6395@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Kind people,

Here's something I came up with for finding whether a PostgreSQL 7.4
user is in a group.

Cheers,
D

CREATE OR REPLACE FUNCTION in_group (text, text) RETURNS BOOLEAN AS '
DECLARE
the_user ALIAS FOR $1;
the_group ALIAS FOR $2;
dummy text; -- SELECT INTO dummy because PERFORM always returns true.
-- Is this a bug?
BEGIN
SELECT INTO dummy u.usename
FROM
pg_user u
, pg_group g
WHERE
u.usename = the_user
AND g.groname = the_group
AND u.usesysid = ANY (g.grolist);

IF FOUND
THEN
RETURN true;
ELSE
RETURN false;
END IF;
END;
' LANGUAGE 'plpgsql' STRICT IMMUTABLE;
--
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-11-21 04:27:31 Re: logical column position
Previous Message Christopher Kings-Lynne 2003-11-21 01:38:50 Re: Release cycle length