Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a number of GRANTs I need to make in a Postgres databas -- Is it possible to put statements like

GRANT SELECT ON TABLE tablename_xxx TO xxx_group;

inside of a Postgres SQL function?

share|improve this question
    
"in side the postgres function." <-- The what?? –  Chris S Jan 25 '12 at 21:12
    
I mean - inside the user defined function –  Trip Jan 25 '12 at 21:20
1  
Yep, you can do that. Don't know why you would want to, but you can. –  Chris S Jan 25 '12 at 21:25
    
Thankyou Chris Basically I have a set of Grant commands I want to write a loop and pass the table names as parameters so that the function can be very minimal –  Trip Jan 25 '12 at 22:32

1 Answer 1

I believe you can do this, but in practice you are probably better off writing an external script to do it instead: Having a Postgres function (pl/pgsql or similar) hanging around just to do GRANTs is overkill, where a simple shell script (or PowerShell if you're on Windows) could do the job.

I consider GRANT to be part of the DDL functionality of Postgres, and it's generally a good practice to not write functions that use DDL statements (Just as you would probably not write a function to create tables).

share|improve this answer
    
You are correct, as per the suggestion I wrote the external script and its working great. Thanku –  Trip Feb 10 '12 at 18:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.