Granting permission to users on different schema

后端 未结 4 856
长情又很酷
长情又很酷 2021-02-14 21:20

I have tables in Schema A. I created views in Schema B using the tables in schema A.

I want to grant permissions to a user to select the data from view in Schema B.

4条回答
  •  爱一瞬间的悲伤
    2021-02-14 22:02

    Only by connecting as user A at some point. You can still do it in one script if you really want to:

    connect userA/passwordA
    grant select on my_table to userB;
    connect userB/passwordB
    create view my_view as select * from userA.my_table;
    

    Of course now you have a script lying around which exposes two sets of user credentials to anyone who can read it. So something to think hard about before doing in production, for example.

    If you want other users to be able to select from the view, you don't need to grant explicit permissions on userA.my_table to them; as long as the view owner can see the underlying table, other users just need to be able to see the view. Which is often kinda the point (or one of them) as you can restrict the view to only expose selected data from the underlying table to the rest of the world. I assume you have a reason for not creating the view in schema A.

    I'm not sure if you're really asking about granting select to user B with admin option so that user B can then grant select on user A's table to other people. If that's possible, it doesn't sound like a good idea, and isn't necessary for the view to work.

提交回复
热议问题