I have access to db with a lot of schemas (each schema - separate store). And this db have not information_schema
.
Next code gives me a list with over 1K schemas:
SELECT nspname FROM pg_namespace WHERE nspname LIKE 'cabinet%'
I need to count rows in some table, if it exist, for every scheme in that list. Something like:
for scheme in scheme_list:
SELECT scheme, count(*) FROM scheme.table_i_need
Output should contain schema_name and some integer value.
So long I was not able to find the answer, please help.
UPD: Thanks to Vao Tsun, I was able to even write this loop over text array with schema names.
do $$
declare
m text[];
a text[] := array[['cabinet1003052234'], ['cabinet1027326445'], ['cabinet1062828216'], ['cabinet108034857']];
s text;
begin
FOREACH m SLICE 1 IN ARRAY a LOOP
execute format('select count(*) from %I.react_order', CAST (m[1] AS regnamespace)) into s;
raise info '%: %', m,s;
end loop;
end;
$$
;