Re: Returns setof record PG/PLSQL - Mailing list pgsql-general

From John Wells
Subject Re: Returns setof record PG/PLSQL
Date
Msg-id 1124069142.21366.33.camel@localhost.localdomain
Whole thread Raw
In response to Re: Returns setof record PG/PLSQL  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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


pgsql-general by date:

Previous
From: "Jim Buttafuoco"
Date:
Subject: Re: Returns setof record PG/PLSQL
Next
From: Frank Rittinger
Date:
Subject: Re: Upgrading 8.0.2 to 8.0.3 on Windows XP