0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

指定したロールに属するロールを再帰クエリで検索する

Posted at

指定したロール名に属する、全てのロール名を検索する例。

以下のSQLでは user_x というロール名が包含する全てのロール名を検索する。

WITH RECURSIVE t AS (
  SELECT usesysid as roleid FROM pg_user WHERE usename = 'user_x'
UNION ALL
  SELECT member as roleid FROM pg_auth_members pam JOIN t ON (pam.roleid= t.roleid)
) SELECT pu.usename FROM t JOIN pg_user pu ON (t.roleid = pu.usesysid);

指定したロールIDに属する、全てのロールIDを検索するSQLの例。

以下のSQLでは 16396 というロールidが包含する全てのロールidを検索する。

WITH RECURSIVE t AS (
  SELECT usesysid roleid FROM pg_user WHERE usesysid = 16396
UNION ALL
  SELECT member as roleid FROM pg_auth_members pam JOIN t ON (pam.roleid= t.roleid)
) SELECT roleid FROM t;
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?