千家信息网

postgresql with子句

发表于:2024-11-19 作者:千家信息网编辑
千家信息网最后更新 2024年11月19日,1、查看当前数据库版本mydb=# select version(); version
千家信息网最后更新 2024年11月19日postgresql with子句

1、查看当前数据库版本

mydb=# select version();                                                 version                                                 --------------------------------------------------------------------------------------------------------- PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit


2、with子句,查看role和组的关系

with temp as

(select a.rolname,a.rolsuper,m.member from pg_authid a join pg_auth_members m

on a.oid=m.roleid)

select temp.rolname,temp.rolsuper,s.rolname as groupname from temp join pg_authid s

on temp.member = s.oid;



mydb=# with temp as mydb-# (select  a.rolname,a.rolsuper,m.member from  pg_authid a join pg_auth_members m mydb(# on a.oid=m.roleid)mydb-# select temp.rolname,temp.rolsuper,s.rolname as groupname from temp join pg_authid s mydb-# on temp.member = s.oid;       rolname        | rolsuper | groupname  ----------------------+----------+------------ pg_read_all_settings | f        | pg_monitor pg_read_all_stats    | f        | pg_monitor pg_stat_scan_tables  | f        | pg_monitor



0