title: create CURSOR for dynamic table search PostgreSQL
body: <p>SQL server(MSSQL) CURSOR  dynamic table search :</p>
  
  <pre><code> DECLARE @tbl    sysname,
              @sql    nvarchar(4000),
              @params nvarchar(4000),
              @count  int
  
  DECLARE tblcur CURSOR STATIC LOCAL FOR
     SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_NAME like 'abc%'
  OPEN tblcur
  
  WHILE 1 = 1
  BEGIN
     FETCH tblcur INTO @tbl
     IF @@fetch_status &lt;&gt; 0
        BREAK
  
     SELECT @sql =
     N' SELECT @cnt = COUNT(*) FROM dbo.' + quotename(@tbl) '
     EXEC sp_executesql @sql, @cnt = @count OUTPUT
  
     PRINT @tbl + ': ' + convert(varchar(10), @count) + ' modified rows.'
  END
  
  DEALLOCATE tblcur
  </code></pre>
  
  <p>I want this for PostgreSQL.</p>
  
  <p>what i have done yet :</p>
  
  <pre><code> DO $$
  DECLARE
      i varchar;
      searchsql text;
      temp int;
  BEGIN
  FOR i IN select table_schema from information_schema.columns where table_schema like 'abc%' 
  LOOP
  searchsql := 'select count(*) from' || quote_ident(i) ;
  
      EXECUTE searchsql;
      --IF (temp &gt; 0) THEN
      --  RAISE NOTICE  'Schema % % and count' ,i , temp;
      --END IF;
      RAISE NOTICE  'Schema %' ,i ;
      RAISE NOTICE  'Script %' ,searchsql ;
  END LOOP;
  END
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>i am new PostgreSQL.</p>
  
  <p>1.How to get count just like sql server (MSSQL)?</p>
  
  <p>2.Is any better way to do this ?</p>
  
  <p>Thanks in Advance .</p>