title: postgresql change all sequences with for loop
body: <p>I have sequences like table_name_sq in postgresql for all tables.
  For example;</p>
  
  <pre><code>seqtest-&gt; seqtest_sq
  seqtest2-&gt; seqtest2_sq
  </code></pre>
  
  <p>I need to change all sequences in database.
  (I cannot run query for every tables manually)</p>
  
  <p>I can get tables and make sequence string</p>
  
  <pre><code>select table_name || '_sq' as sequence_name from information_schema.tables where table_catalog='test' and table_schema='public'
  </code></pre>
  
  <p>I can change sequence value for specified table</p>
  
  <pre><code>select setval('seqtest_sq',(select max(id) from seqtest)+1)
  </code></pre>
  
  <p>But I cannot merge these two.
  I think should use for loop but that I could not make that work.</p>
  
  <p><strong>CODE IS:</strong></p>
  
  <pre><code>DO $$
  DECLARE 
  i RECORD;
  BEGIN
      FOR i IN (select table_name from information_schema.tables) LOOP
           EXECUTE 'SELECT count(*) FROM ' || i;
      END LOOP;
  END$$;
  </code></pre>
  
  <p><strong>OUTPUT is:</strong></p>
  
  <pre><code>ERROR:  syntax error at or near ")"
  LINE 1: SELECT count(*) FROM (seqtest)
                                       ^
  QUERY:  SELECT count(*) FROM (seqtest)
  CONTEXT:  PL/pgSQL function inline_code_block line 6 at EXECUTE
  ********** Error **********
  
  ERROR: syntax error at or near ")"
  SQL state: 42601
  Context: PL/pgSQL function inline_code_block line 6 at EXECUTE
  </code></pre>
  
  <p>Also I printed table names with for loop but table names come with parentheses.</p>
  
  <p><strong>HERE is CODE</strong></p>
  
  <pre><code>DO $$
  DECLARE 
  i RECORD;
  BEGIN
      FOR i IN (select table_name from information_schema.tables where table_catalog='test' and table_schema='public') LOOP
      raise notice 'Value: %',i;
      END LOOP;
  END$$;
  </code></pre>
  
  <p><strong>HERE is OUTPUT:</strong></p>
  
  <pre><code>NOTICE:  Value: (seqtest)
  NOTICE:  Value: (seqtest2)
  </code></pre>
  
  <p>I think it is enough for me to get rid of this parentheses.</p>
  
  <p>Would you help me to build a proper loop or find a easy way to achive this?</p>