Search Postgresql Archives

Returns setof record PG/PLSQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In my quest to create a function that counts rows for all user tables in
the database, I've written the following:
--
drop function generate_table_count ();
create or replace function generate_table_count () returns setof record
as '
declare   
  tname record;
  count record;
  table text;
begin
	for tname in select table_name from information_schema.tables 
               where table_schema = ''public'' loop
		for count in execute ''select ''''''  || 
        quote_ident(tname.table_name)     || 
        '''''' as name, count(*)  from '' || 
        quote_ident(tname.table_name) loop			
			table := count.name;                 		
			return next;
		end loop;
	end loop;
	return;
end;
' language plpgsql;
--

Problem is, I can't figure out what parameters to pass to "return next;"
to make this return properly, and can't find an example in the
documentation.  I have it working by defining the function to return
"setof text" and then do return next as:

--
return next table || '' '' || count.count;
--

However, I really want each result (table name and count) to have it's
own column.

Can someone help me out or point me in the direction of documentation
that will show an example?  It shouldn't be this hard, it seems.

Thanks, as always, for your help,
John


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux