From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | John Wells <jb(at)sourceillustrated(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Seeking PL/PGSQL example |
Date: | 2005-08-12 22:46:10 |
Message-ID: | 20050812224610.GA98964@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Aug 12, 2005 at 05:26:50PM -0400, John Wells wrote:
>
> With PL/PGSQL, how would I roll through all tables in my database and
> print the table name, along with the row count of that table?
You can get the schemas and tables from the system catalogs or from
the Information Schema (the latter available in 7.4 and later).
http://www.postgresql.org/docs/8.0/static/catalogs.html
http://www.postgresql.org/docs/8.0/static/information-schema.html
To loop through query results, see "Looping Through Query Results"
in the PL/pgSQL documentation. See also "Executing Dynamic Commands"
and "RETURN NEXT".
http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING
http://www.postgresql.org/docs/8.0/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING
For row counts you can use COUNT; if an estimate will suffice, you
could use pg_class.reltuples.
http://www.postgresql.org/docs/8.0/static/functions-aggregate.html
http://www.postgresql.org/docs/8.0/static/catalog-pg-class.html
--
Michael Fuhr
From | Date | Subject | |
---|---|---|---|
Next Message | Chris Travers | 2005-08-12 23:13:04 | Re: Seeking PL/PGSQL example |
Previous Message | John Wells | 2005-08-12 21:26:50 | Seeking PL/PGSQL example |