Jump to content
Fórum Script Brasil
  • 0

Listar permissões de uma ROLE em uma unica coluna


Question

Preciso Listar as permissões das ROLES de uma forma que todas apareçam em uma unica coluna (attributes)

Meu select esta assim:
select rolname as "Name", oid as "Role id", 

CASE WHEN rolsuper OR rolinherit OR rolcreatedb OR rolcanlogin OR rolreplication THEN CAST ('SuperRole, Role Inherit, Create Database, Can Login, Can Replicate' as pg_catalog.text)

ELSE CAST ('' as pg_catalog.text) 
END AS "attributes"
FROM pg_catalog.pg_roles;

Resultado:

       Name                  | Role id |                attributes
-------------------+---------+-------------+--------------------------------------------------------------------
 pg_signal_backend |    4200  |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 postgres                   |      10     |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 admin                        |   24641 |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 administrador          |   24643 |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 teste2                        |   24653 |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 teste3                        |   24670 |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 teste4                       |   24671  |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate

 

Porem esta trazendo os mesmo atributos para todos as roles, independe de suas permissões serem diferentes.

Preciso listar apenas as permissões que cada roleo tem, na coluna attributes.

Algo parecido com:

       Name                  | Role id |                attributes
-------------------+---------+-------------+--------------------------------------------------------------------
 pg_signal_backend |    4200  |  Can Login
 postgres                   |      10     |  SuperRole, Create Database, Can Login, Can Replicate
 admin                        |   24641 |  SuperRole, Role Inherit, Create Database, Can Login, Can Replicate
 administrador          |   24643 |  SuperRole,  Create Database, Can Login, Can Replicate
 teste2                        |   24653 |  , Role Inherit, Can Login, Can Replicate
 teste3                        |   24670 |  Create Database, Can Login
 teste4                       |   24671  |   Role Inherit,  Can Login

se alguém puder me ajudar, agradeço

Abraço!

 

Edited by rodrigolss
correção de informações
Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148692
    • Total Posts
      644525
×
×
  • Create New...