Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 72CA09FB488 for ; Fri, 3 Aug 2007 04:20:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 57705-05 for ; Fri, 3 Aug 2007 04:20:44 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 8B8CC9FB460 for ; Fri, 3 Aug 2007 04:20:47 -0300 (ADT) Received: (qmail 28716 invoked by uid 0); 3 Aug 2007 07:20:45 -0000 Received: from 194.11.223.215 by www135.gmx.net with HTTP; Fri, 03 Aug 2007 09:20:45 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-1" Date: Fri, 03 Aug 2007 09:20:45 +0200 From: "Christian Kindler" Message-ID: <20070803072045.152170@gmx.net> MIME-Version: 1.0 Subject: Re: Count of rows To: pgsql-sql@postgresql.org X-Authenticated: #27759442 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX18r0tUkUO0rmkCCfT5H6iOewMu0V3T8hCGiIrembv irGGSuqkE+XW9eAAohRLbQxII5ILkDlVnVTg== Content-Transfer-Encoding: 8bit X-GMX-UID: I7rQEjYbbXB+UDfhlTU25R0iLyUmZYgi X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.013 tagged_above=0 required=5 tests=BAYES_50=0.001, FAKE_REPLY_C=2.012 X-Spam-Level: ** X-Archive-Number: 200708/17 X-Sequence-Number: 28955 do this via execute in a stored procedure - something like this (written on the flow - untested!) returns setof text declare my_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