Skip site navigation (1) Skip section navigation (2)

Re: grant execute on many functions

From: Jean-Denis Giguere <jdenisgiguere(at)fastmail(dot)fm>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org
Subject: Re: grant execute on many functions
Date: 2004-06-30 16:32:37
Message-ID: 40E2EB25.1070005@fastmail.fm (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-hackers
Tom Lane wrote:
> Doug Quale <quale1(at)charter(dot)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



In response to

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2004-06-30 17:11:14
Subject: Re: ODBC Developers
Previous:From: Joshua D. DrakeDate: 2004-06-30 16:19:35
Subject: Re: Win32 version question

pgsql-admin by date

Next:From: Tom LaneDate: 2004-06-30 17:22:23
Subject: Re: Postgres Version 7.4.3
Previous:From: Lee WuDate: 2004-06-30 16:27:05
Subject: Postgres Version 7.4.3

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group