Redshift: Total Row Count for all tables for a particular user -


we use periscope charges(i think) total number of rows present in tables give access to.

my question is: given user periscope, how obtain total count of rows in tables user periscope has access to?

e.g. if user periscope can access 2 tables: t1 count 8 , t2 count 2, total count should 10.

i got tables answer(excluding 'pg_tables' , 'information_schema') don't know how go next:

select cast(schemaname varchar), cast(  objectname varchar)      (     select          schemaname         ,objectname         ,usename         ,has_table_privilege(usrs.usename, fullobj, 'select') sel         ,has_table_privilege(usrs.usename, fullobj, 'insert') ins         ,has_table_privilege(usrs.usename, fullobj, 'update') upd         ,has_table_privilege(usrs.usename, fullobj, 'delete') del         ,has_table_privilege(usrs.usename, fullobj, 'references') ref             (         select schemaname, 't' obj_type, tablename objectname, schemaname + '.' + tablename fullobj pg_tables         schemaname not in ('pg_internal')         union         select schemaname, 'v' obj_type, viewname objectname, schemaname + '.' + viewname fullobj pg_views         schemaname not in ('pg_internal')         ) objs         ,(select * pg_user) usrs     order fullobj     ) (sel = true or ins = true or upd = true or del = true or ref = true) , usename = 'periscope' , schemaname not in ('information_schema', 'pg_catalog'); 

if have elegant solution, please let me know!

this should give need:

select sum(b.reltuples)  (     select          schemaname         ,objectname         ,usename         ,has_table_privilege(usrs.usename, fullobj, 'select') sel         ,has_table_privilege(usrs.usename, fullobj, 'insert') ins         ,has_table_privilege(usrs.usename, fullobj, 'update') upd         ,has_table_privilege(usrs.usename, fullobj, 'delete') del         ,has_table_privilege(usrs.usename, fullobj, 'references') ref         (         select schemaname, 't' obj_type, tablename objectname, schemaname + '.' + tablename fullobj pg_tables         schemaname not in ('pg_internal')         union         select schemaname, 'v' obj_type, viewname objectname, schemaname + '.' + viewname fullobj pg_views         schemaname not in ('pg_internal')         ) objs         ,(select * pg_user) usrs     order fullobj ) join  (     select          nspname schemaname,relname,reltuples     pg_class c     left join pg_namespace n on (n.oid = c.relnamespace)     order reltuples desc ) b on (a.schemaname = b.schemaname , a.objectname = b.relname) (sel = true or ins = true or upd = true or del = true or ref = true) , usename = 'periscope' , a.schemaname not in ('information_schema', 'pg_catalog'); 

Comments