Re: Number of rows of a table

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: vittorio <vdemart1(at)tin(dot)it>, pgsql-general(at)postgresql(dot)org
Subject: Re: Number of rows of a table
Date: 2005-10-21 22:56:43
Message-ID: 20051021225643.GZ16682@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Oct 19, 2005 at 08:23:35AM +0900, Michael Glaesemann wrote:
>
> On Oct 19, 2005, at 2:29 , vittorio wrote:
>
> >Using psql how can I ask postgresql to show the actual number of
> >rows of a
> >table?
>
> For table foo,
>
> select count(*) from foo;
>
> An up-to-date count of the number of actual rows is not stored some
> place in the database. If an estimate is adequate for your purposes,
> you might want to look at some of the system tables which track row
> counts for query planning strategy. I don't recall offhand which
> column of which system table you'd want to look at, unfortunately.

You want reltuples from pg_class, but keep in mind you need to account
for schemas using relnamespace. Or install newsysviews
(http://pgfoundry.org/projects/newsysviews) and:

SELECT estimated_rows
FROM pg_sysviews.pg_user_tables
WHERE schema_name = 'schema'
AND table_name = 'table'
;
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Douglas McNaught 2005-10-21 23:01:08 Re: How much slower are numerics?
Previous Message Redefined Horizons 2005-10-21 22:52:33 Newbie Questions