Re: Count of rows - Mailing list pgsql-sql

From Christian Kindler
Subject Re: Count of rows
Date
Msg-id 20070803072045.152170@gmx.net
Whole thread Raw
In response to Count of rows  (Paul Lambert <paul.lambert@autoledgers.com.au>)
List pgsql-sql
do this via execute in a stored procedure - something like this (written on the flow - untested!)

returns setof text

declaremy_record record;my counter as bigint;

begin

for my_record in   select tablename from pg_tables where  schemaname = 'public' 
loop  execute into counter      'select count(*) from ' || my_record.tablename ;  return next my_record.tablename || ':
'|| counter::text;
 

end loop;  return null;

end;


On Fri, August 3, 2007 7:35 am, Paul Lambert wrote:
> What's the best way to count how many rows are in each table via SQL? Or
> is it even possible?
> 
> I'm trying something like:
> 
> select tablename, count(*) from (select tablename from pg_tables where
> schemaname = 'public') as test group by tablename;
> 
> But obviously this just gives a count of 1 for each table in the public
> schema.
> 
> Can it be done or would I have to write a function?
> 
> --
> Paul Lambert
> Database Administrator
> AutoLedgers
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly
> 


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger


pgsql-sql by date:

Previous
From: Paul Lambert
Date:
Subject: Count of rows
Next
From: Dani Castaños
Date:
Subject: Re: Foreign Key inter databases