Unix Technical Forum

Number of rows of a table

This is a discussion on Number of rows of a table within the Pgsql General forums, part of the PostgreSQL category; --> Using psql how can I ask postgresql to show the actual number of rows of a table? Ciao Vittorio ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 07:30 AM
vittorio
 
Posts: n/a
Default Number of rows of a table

Using psql how can I ask postgresql to show the actual number of rows of a
table?
Ciao
Vittorio

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 07:30 AM
Michael Glaesemann
 
Posts: n/a
Default Re: Number of rows of a table


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.

Michael Glaesemann
grzm myrealbox com




---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 07:30 AM
Mike Nolan
 
Posts: n/a
Default Re: Number of rows of a table

> Using psql how can I ask postgresql to show the actual number of rows of a
> table?


What do you mean by 'actual number of rows'?

Is there a reason you can't just do:
select count(*) from this_table:
--
Mike Nolan

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 07:35 AM
Jim C. Nasby
 
Posts: n/a
Default Re: Number of rows of a table

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@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com