From: Jean-Denis Giguere <jdenisgiguere@fastmail.fm>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-admin@postgresql.org
Subject: Re: grant execute on many functions
Date: Wed, 30 Jun 2004 12:32:37 -0400
Message-ID: <40E2EB25.1070005@fastmail.fm> (raw)
In-Reply-To: <8987.1088608020@sss.pgh.pa.us>
References: <40E1E1A9.8080207@fastmail.fm>
<40E1ECEF.5090007@joeconway.com>
<3318.1088567114@sss.pgh.pa.us>
<40E23F72.4000108@joeconway.com>
<87oen1quxt.fsf@charter.net>
<8987.1088608020@sss.pgh.pa.us>
Tom Lane wrote:
> Doug Quale <quale1@charter.net> writes:
>
>>test=# select oid::regprocedure from pg_proc order by oid::regprocedure;
>
>
>>doesn't sort the way I would expect.
>
>
> Nope, it'd just be ordering by the numeric OID. If you added a cast
> procedure as we were just discussing, you could order by
> oid::regprocedure::text and get what I suppose you're expecting.
Is this cast procedure is correct oid::regprocedure::text ?
When I try this, I get
ERROR: cannot cast type regprocedure to text.
Here is a small bash script to grant execute on many functions. (There
are some strange error sometime, but I'm not able to reproduce the bug...)
########################################################
#!/bin/bash
#Usage: grantexfct schema groupe
schema=$1
groupe=$2
SQL="SELECT p.oid::regprocedure from pg_proc p
LEFT JOIN pg_namespace n ON p.pronamespace=n.oid
where n.nspname like '$schema';"
LIST=`psql -c "$SQL" -A -t -U postgres servweb`
echo $LIST
for fct in $LIST
do
echo $fct
SQL="GRANT EXECUTE ON FUNCTION $fct TO GROUP $groupe;"
psql -c "$SQL" -U postgres servweb
done
exit 0
########################################################
This is the pl/pgsql function. It is broken because I'm not able to cast
::regprocedure to ::text
Maybye there are others bugs...
########################################################
--grant_exec(SCHEMA,GROUP)
-- Grants execute on every functions of SCHEMA to group GROUP
--
DECLARE
schem ALIAS FOR $1;
grp ALIAS FOR $2;
obj record;
num integer;
BEGIN
num:=0;
FOR obj IN SELECT p.oid::regprocedure as funct
FROM pg_proc p
LEFT JOIN pg_namespace n ON p.pronamespace=n.oid
where n.nspname like schem LOOP
EXECUTE 'GRANT EXECUTE ON FUNCTION ' || schem || '.' ||
obj.funct ::text || ' TO GROUP ' || grp;
num := num + 1;
END LOOP;
RETURN num;
END;
#########################################################
Any comment is welcome.
Thank you to everyone who has contributed to this "solution".
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: jdenisgiguere@fastmail.fm, tgl@sss.pgh.pa.us
Subject: Re: grant execute on many functions
In-Reply-To: <40E2EB25.1070005@fastmail.fm>
References: <40E1E1A9.8080207@fastmail.fm> <40E1ECEF.5090007@joeconway.com> <3318.1088567114@sss.pgh.pa.us> <40E23F72.4000108@joeconway.com> <87oen1quxt.fsf@charter.net> <8987.1088608020@sss.pgh.pa.us> <40E2EB25.1070005@fastmail.fm>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox