Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GRANT SELECT privilege to ALL sequences using one statement

Tags:

sql

postgresql

How can I grant the SELECT privilege on all sequences to a user using one statement? Somthing like:

GRANT SELECT ON <ALL SEQUENCES???> TO myUser
like image 404
markus Avatar asked Sep 12 '11 10:09

markus


People also ask

Which of the privilege can be granted on a sequence?

The following privileges are valid for sequences: SELECT: Execute functions CURRVAL and NEXTVAL on the specified sequences. ALTER: Modify a sequence's DDL with ALTER SEQUENCE.

How do you write a grant for a sequence?

GRANT CREATE ANY SEQUENCE, ALTER ANY SEQUENCE, DROP ANY SEQUENCE, SELECT ANY SEQUENCE TO my_user; The owner of a sequence has full privileges on the sequence. Another user can be given access to the sequence by granting the SELECT object privilege.


3 Answers

In PostgreSQL 9.x, you can grant permissions on all sequences in one schema to a role. The syntax is

GRANT SELECT ON ALL SEQUENCES IN SCHEMA schema_name     TO role_name 

The role can be either a group role or a login role (user name).

like image 137
Mike Sherrill 'Cat Recall' Avatar answered Oct 14 '22 00:10

Mike Sherrill 'Cat Recall'


This will be very useful in the future:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA schema_name TO your_user; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA schema_name TO your_user; GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA schema_name TO your_user; 
like image 37
Oswaldo Rodriguez Gonzalez Avatar answered Oct 14 '22 01:10

Oswaldo Rodriguez Gonzalez


The accepted answer dont worked for me on 9.1. The below sentence did work:

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO user;
like image 27
Diego Quirós Avatar answered Oct 14 '22 01:10

Diego Quirós