title: How to loop over list of schemas in POSTGRESQL
body: <p>I have access to db with a lot of schemas (each schema - separate store). And this db have not <code>information_schema</code>.</p>
  
  <p>Next code gives me a list with over 1K schemas:</p>
  
  <pre><code>SELECT nspname FROM pg_namespace WHERE nspname LIKE 'cabinet%'
  </code></pre>
  
  <p>I need to count rows in some table, if it exist, for every scheme in that list. Something like:</p>
  
  <pre><code>for scheme in scheme_list:
      SELECT scheme, count(*) FROM scheme.table_i_need
  </code></pre>
  
  <p>Output should contain schema_name and some integer value.</p>
  
  <p>So long I was not able to find the answer, please help.</p>
  
  <p><strong>UPD:</strong> Thanks to <a href="https://stackoverflow.com/users/5315974/vao-tsun">Vao Tsun</a>, I was able to even write this loop over text array with schema names.</p>
  
  <pre><code>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;
  $$
  ;
  </code></pre>