Re: Number of rows in a table

Lists: pgsql-novice
From: "Louise Cofield" <lcofield(at)box-works(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Number of rows in a table
Date: 2003-08-25 16:06:28
Message-ID: 001001c36b22$d7ac4fc0$7801a8c0@Louise
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

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!


From: "paul butler" <paul(at)entropia(dot)co(dot)uk>
To: "Louise Cofield" <lcofield(at)box-works(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Number of rows in a table
Date: 2003-08-25 16:08:05
Message-ID: 3F4A4275.29756.2B4313E8@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

From: "Louise Cofield" <lcofield(at)box-works(dot)com>
To: <pgsql-novice(at)postgresql(dot)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!
>
>
>
>
>
>
>
>


From: Tomka Gergely <tomka(at)zeus(dot)gau(dot)hu>
To: Louise Cofield <lcofield(at)box-works(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Number of rows in a table
Date: 2003-08-25 16:14:26
Message-ID: Pine.LNX.4.33.0308251814050.31338-100000@zeus.gau.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

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..."


From: Jason Hihn <jhihn(at)paytimepayroll(dot)com>
To: Louise Cofield <lcofield(at)box-works(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Number of rows in a table
Date: 2003-08-25 16:18:28
Message-ID: NGBBLHANMLKMHPDGJGAPOEIICMAA.jhihn@paytimepayroll.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Count()?

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of Louise Cofield
Sent: Monday, August 25, 2003 12:06 PM
To: pgsql-novice(at)postgresql(dot)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!


From: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
To: Tomka Gergely <tomka(at)zeus(dot)gau(dot)hu>
Cc: Louise Cofield <lcofield(at)box-works(dot)com>, pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Number of rows in a table
Date: 2003-08-25 16:23:24
Message-ID: 1061828603.503.7.camel@billy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

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


From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: PgSQL Novice ML <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Number of rows in a table
Date: 2003-08-25 17:41:24
Message-ID: 1061833284.11922.65.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

On Mon, 2003-08-25 at 11:08, paul butler wrote:
> From: "Louise Cofield" <lcofield(at)box-works(dot)com>
> To: <pgsql-novice(at)postgresql(dot)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(dot)l(dot)johnson(at)cox(dot)net
Jefferson, LA USA

PETA - People Eating Tasty Animals


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
Cc: PgSQL Novice ML <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Number of rows in a table
Date: 2003-08-25 20:53:18
Message-ID: 10653.1061844798@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)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


From: Christopher Browne <cbbrowne(at)libertyrms(dot)info>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Number of rows in a table
Date: 2003-09-03 03:15:11
Message-ID: 60isoa4l6o.fsf@dev6.int.libertyrms.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

ron(dot)l(dot)johnson(at)cox(dot)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)