PostgreSQL – 如何授予用户修改表列的访问权限?

huangapple go评论53阅读模式
英文:

Postgresql - How to grant a user access to altering a table column?

问题

I asked chatGPT but the suggestions didn't work. It came back saying:

GRANT ALTER ON TABLE my_schema.table_name TO my_user;

Running this game me an error unrecognized privilege type "alter"

It then came back with the following:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA my_schema TO my_user;

This seems excessive? Is this the only way to grant alter privileges?

EDIT:

  • The final comment that chatGPT provided doesn't actually work

我向ChatGPT提问,但建议没有起作用。它返回以下内容:

GRANT ALTER ON TABLE my_schema.table_name TO my_user;

运行这个命令会出现错误,提示"unrecognized privilege type 'alter'"

然后它返回以下内容:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA my_schema TO my_user;

这似乎过于冗余?这是授予修改权限的唯一方法吗?

编辑:

  • ChatGPT最后提供的评论实际上不起作用。
英文:

I asked chatGPT but the suggestions didn't work. It came back saying:

GRANT ALTER ON TABLE my_schema.table_name TO my_user;

Running this game me an error unrecognized privilege type "alter"

It then came back with the following:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA my_schema TO my_user;

This seems excessive? Is this the only way to grant alter privileges?

EDIT:

  • The final comment that chatGPT provided doesn't actually work

答案1

得分: 2

精细手册中:

若要使用ALTER TABLE,您必须拥有该表。

GRANT不会更改这一行为,您必须是所有者。


为了允许其他角色更改表和其他数据库对象,您可以将这些角色授予所有者:

GRANT owner_of_your_objects TO my_user;

这将赋予角色"my_user"与角色"owner_of_your_objects"相同的权限! 但要小心,因为现在也允许DROP TABLE。 您可以编写事件触发器以避免这种情况。

英文:

From the fine manual:

> You must own the table to use ALTER TABLE.

GRANT will not change this behavior, you must be the owner.


What you could do to allow other roles to change tables and other database objects, is to grant these roles to the owner:

GRANT owner_of_your_objects TO my_user;

This gives the role "my_user" the same (!) privileges as the role "owner_of_your_objects". But be careful because DROP TABLE is now also allowed. You could write an event_trigger to avoid this.

huangapple
  • 本文由 发表于 2023年3月7日 16:32:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定