Thread: Number of rows in a table

Number of rows in a table

From
"Louise Cofield"
Date:

I haven’t been able to figure out how to determine the number of populated rows in a table – such as “select max(rownum)” in Oracle.

 

Thanks!

 

 

 

Re: Number of rows in a table

From
Tomka Gergely
Date:
2003-08-25 ragyogó napján Louise Cofield ezt üzente:

> I haven't been able to figure out how to determine the number of
> populated rows in a table - such as "select max(rownum)" in Oracle.

select count(*) from usw.; ?

--
Tomka Gergely
"S most - vajon barbárok nélkül mi lesz velünk?
Ők mégiscsak megoldás voltak valahogy..."


Re: Number of rows in a table

From
Jason Hihn
Date:
Count()?
 
-----Original Message-----
From: pgsql-novice-owner@postgresql.org [mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Louise Cofield
Sent: Monday, August 25, 2003 12:06 PM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] Number of rows in a table

I haven’t been able to figure out how to determine the number of populated rows in a table – such as “select max(rownum)” in Oracle.

 

Thanks!

 

 

 

Re: Number of rows in a table

From
"paul butler"
Date:
From:               "Louise Cofield" <lcofield@box-works.com>
To:                 <pgsql-novice@postgresql.org>
Subject:            [NOVICE] Number of rows in a table
Date sent:          Mon, 25 Aug 2003 10:06:28 -0600

SELECT count(ColumnName) FROM TableName;
should do the trick
Paul Butler
> I haven't been able to figure out how to determine the number of
> populated rows in a table - such as "select max(rownum)" in Oracle.
>
>
>
> Thanks!
>
>
>
>
>
>
>
>



Re: Number of rows in a table

From
Nabil Sayegh
Date:
Am Mo, 2003-08-25 um 18.14 schrieb Tomka Gergely:
> 2003-08-25 ragyogó napján Louise Cofield ezt üzente:
>
> > I haven't been able to figure out how to determine the number of
> > populated rows in a table - such as "select max(rownum)" in Oracle.
>
> select count(*) from usw.; ?

Keep i mind Louise, that this is an aggregate function, i.e. all other
columns you want to get in the same query must be GROUPed or used in an
aggregate function, too.

bye
--
 e-Trolley Sayegh & John, Nabil Sayegh
 Tel.: 0700 etrolley /// 0700 38765539
 Fax.: +49 69 8299381-8
 PGP : http://www.e-trolley.de


Re: Number of rows in a table

From
Ron Johnson
Date:
On Mon, 2003-08-25 at 11:08, paul butler wrote:
> From:               "Louise Cofield" <lcofield@box-works.com>
> To:                 <pgsql-novice@postgresql.org>
> Subject:            [NOVICE] Number of rows in a table
> Date sent:          Mon, 25 Aug 2003 10:06:28 -0600
>
> SELECT count(ColumnName) FROM TableName;
> should do the trick

Well yes, but in most other databases, there is a system table that
stores the approximate number of records in each table, and querying
that system table is a *lot* faster than sequentially reading a 100M
row table.

> > I haven't been able to figure out how to determine the number of
> > populated rows in a table - such as "select max(rownum)" in Oracle.

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

PETA - People Eating Tasty Animals


Re: Number of rows in a table

From
Tom Lane
Date:
Ron Johnson <ron.l.johnson@cox.net> writes:
> Well yes, but in most other databases, there is a system table that
> stores the approximate number of records in each table, and querying
> that system table is a *lot* faster than sequentially reading a 100M
> row table.

If an approximate number is good enough, see pg_class.reltuples.

            regards, tom lane

Re: Number of rows in a table

From
Christopher Browne
Date:
ron.l.johnson@cox.net (Ron Johnson) writes:
> Well yes, but in most other databases, there is a system table that
> stores the approximate number of records in each table, and querying
> that system table is a *lot* faster than sequentially reading a 100M
> row table.

That relation would be pg_class, the domain is called "reltuples."

It is only about as accurate as the last vacuum and/or analyze has
made it, so if you don't fairly regularly vacuum tables, the
approximation may not be very good.  (Which is an argument in favor of
vacuuming fairly often...)
--
select 'cbbrowne' || '@' || 'libertyrms.info';
<http://dev6.int.libertyrms.com/>
Christopher Browne
(416) 646 3304 x124 (land)