Search Postgresql Archives

Re: Returns setof record PG/PLSQL

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

 



On Sun, 2005-08-14 at 20:53 -0400, Tom Lane wrote:
> regression=# create type table_count_result as (table_name text, count bigint);
> CREATE TYPE
> regression=# create or replace function generate_table_count ()              
> regression-# returns setof table_count_result as $$
> regression$# declare
> regression$#   tname record;
> regression$#   count table_count_result;
> regression$# begin
> regression$#   for tname in select table_name from information_schema.tables
> regression$#                where table_schema = 'public'  loop
> regression$#     for count in execute 'select ' || quote_literal(tname.table_name) || ', count(*) from ' || quote_ident(tname.table_name)  loop
> regression$#       return next count;
> regression$#     end loop;
> regression$#   end loop;
> regression$#   return;
> regression$# end$$ language plpgsql;
> CREATE FUNCTION
> regression=# select * from generate_table_count();

Sweet mercy...success.  Thanks...my forehead was a bit bloody from all
the head bashing going on over here... 

I have much to learn about pl/pgsql programming!

Thanks again!
John


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[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