SQL 使用一条语句授予所有序列的 SELECT 特权

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7386321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:05:08  来源:igfitidea点击:

GRANT SELECT privilege to ALL sequences using one statement

sqlpostgresql

提问by markus

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

如何使用一条语句将所有序列的 SELECT 权限授予用户?类似的东西:

GRANT SELECT ON <ALL SEQUENCES???> TO myUser

回答by Mike Sherrill 'Cat Recall'

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

在 PostgreSQL 9.x 中,您可以向角色授予对一个架构中所有序列的权限。该语法

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).

角色可以是组角色或登录角色(用户名)。

回答by Oswaldo Rodriguez Gonzalez

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;

回答by Diego Quirós

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

接受的答案在 9.1 上对我不起作用。下面的句子确实有效:

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO user;

回答by Vishnu Kumar

For Postgres versions lower than 9.0

对于低于 9.0 的 Postgres 版本

psql -d DBNAME -qAt -c "SELECT 'GRANT SELECT ON ' || relname || ' TO USER;' FROM pg_statio_all_sequences WHERE schemaname = 'public'" | psql -d DBNAME

Ref: http://gotochriswest.com/blog/2012/06/11/postgresql-granting-access-to-all-sequences/

参考:http: //gotochriswest.com/blog/2012/06/11/postgresql-granting-access-to-all-sequences/