Re: Returns setof record PG/PLSQL

From: John Wells <jb(at)sourceillustrated(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Returns setof record PG/PLSQL
Date: 2005-08-15 01:25:42
Message-ID: 1124069142.21366.33.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Frank Rittinger 2005-08-15 07:04:34 Re: Upgrading 8.0.2 to 8.0.3 on Windows XP
Previous Message Jim Buttafuoco 2005-08-15 01:06:02 Re: Returns setof record PG/PLSQL