table row count

Поиск
Список
Период
Сортировка
Искать

table row count

От:
"Martin Hurst" <martinh@ix.netcom.com>
Дата:
Is there a way to get the row count of a user table without doing the?

select count(*) from 

which can take some time and even do a table scan if the table has millions
of rows in it.

Are there any system tables or views that hold this value for any given user
table?

-Martin






Re: table row count

От:
Bruno Wolff III <bruno@wolff.to>
Дата:
On Sun, Feb 09, 2003 at 00:08:59 -0500,
  Martin Hurst  wrote:
> Is there a way to get the row count of a user table without doing the?
> 
> select count(*) from 
> 
> which can take some time and even do a table scan if the table has millions
> of rows in it.
> 
> Are there any system tables or views that hold this value for any given user
> table?

No. If you are going to do lots of counts relative to inserts and deletes,
you can keep the count in another table and create triggers to update it.

Re: table row count

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Martin Hurst"  writes:
> Is there a way to get the row count of a user table without doing the?
> select count(*) from 

If this were an easy problem, count() would do it for you ;-)

If you're willing to settle for an approximate answer,
pg_class.reltuples might do.  It's the row count as of the last VACUUM.

			regards, tom lane
FAQ