英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论