Обсуждение: how can we get total records in pg server?

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

how can we get total records in pg server?

От
Bhuvan A
Дата:
Hi all,

how can we get the COUNT of total records in the db server?

hope this could be simple for pg experts.
thankx in advance!

Regards,
Bhuvaneswar.

================================================================================   Eighty percent of married men cheat
inAmerica.  The rest cheat in Europe.                -- Jackie Mason
 
================================================================================



Re: how can we get total records in pg server?

От
Bhuvan A
Дата:
hi all,
consider the pg server with databases
bhuvan
uday
guru

the need is to get TOTAL RECORDS of all the THREE DATABASES or atleast
TOTAL RECORDS of ONE DATABASE.

Seems to be simple.
Thankx in advance and infact i was a newbie. 

Regards, 
Bhuvaneswar.
================================================================================     "There is nothing new under the
sun,but there are lots of old things                   we don't know yet."                -Ambrose Bierce
 
================================================================================

On Mon, 23 Jul 2001, omid omoomi wrote:

> you mean this ?
> select count(*) from tablefoo;
> 
> 
> >From: Bhuvan A <bhuvansql@yahoo.com>
> >To: pgsql-sql@postgresql.org
> >Subject: [SQL] how can we get total records in pg server?
> >Date: Mon, 23 Jul 2001 20:03:42 +0530 (IST)
> >
> >
> >Hi all,
> >
> >how can we get the COUNT of total records in the db server?
> >
> >hope this could be simple for pg experts.
> >thankx in advance!
> >
> >Regards,
> >Bhuvaneswar.
> >================================================================================
> >     Eighty percent of married men cheat in America.  The rest cheat in 
> >Europe.
> >                  -- Jackie Mason
> >================================================================================
> >
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 3: if posting/reading through Usenet, please send an appropriate
> >subscribe-nomail command to majordomo@postgresql.org so that your
> >message can get through to the mailing list cleanly
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 



Re: how can we get total records in pg server?

От
"Josh Berkus"
Дата:
Bhuvan,

> the need is to get TOTAL RECORDS of all the THREE DATABASES or
> atleast
> TOTAL RECORDS of ONE DATABASE.

I guess that many of us are confused by your question.  The total
records in a table are easily counted -- just use count(*).  However, if
your database has many tables, what significance does totalling together
all of the records from those different tables have?  If I have a
reference list with 8 items, do I want to add it to a data table with
300,000 records to make 300,008?  No.

Further, PostgreSQL does not support multi-database operations of any
kind.  So if the data in those three databases needs to interact, you
should probably combine them into one database.

I can't help but feel that there are some basic database concepts you
haven't yet acquired.  Perhaps you've come to Postgres from Filemaker,
and are confused by the difference between "database" and "table".  If
so, you need to start with some basic education before proceeding on to
building a DB application.

In english, I would recommend: "PostgreSQL, Introduction and Concepts"
by Bruce Momjian, as well as "Database Design For Mere Mortals".  If you
would prefer another language, poll the list -- someone may be familiar
with other texts.

-Josh Berkus


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Вложения

Re: how can we get total records in pg server?

От
"Henshall, Stuart - WCP"
Дата:
Hello,Here's a quick function to count the total number of rows in none
system tables:
DROP FUNCTION cnt_rows();
CREATE FUNCTION cnt_rows() RETURNS int4 AS '
DECLAREr RECORD;rb RECORD;tot int4;sqlstr text;
BEGINtot:=0;FOR r IN select * from pg_tables where not tablename like ''pg_%''
LOOP    sqlstr:=''SELECT count(*) AS cnt FROM '' ||
quote_ident(r.tablename) || '';'';    FOR rb IN EXECUTE sqlstr LOOP        RAISE NOTICE ''Number of rows in
%=%'',r.tablename,rb.cnt;        tot:=tot+rb.cnt;    END LOOP;END LOOP;RAISE NOTICE ''Total Number of rows for all none
system
tables=%'',tot;RETURN tot;
END;
' LANGUAGE 'plpgsql';

You'll also need to have the plpgsql language created for your database
(eg: createlang plpgsql testdb)
then just execute the above script then select cnt_rows(); in psql.
-Stuart


ORIGINAL MESSAGE:
hi all,
consider the pg server with databases
bhuvan
uday
guru

the need is to get TOTAL RECORDS of all the THREE DATABASES or atleast
TOTAL RECORDS of ONE DATABASE.

Seems to be simple.
Thankx in advance and infact i was a newbie. 

Regards, 
Bhuvaneswar.
============================================================================
====     "There is nothing new under the sun, but there are lots of old things                   we don't know yet."
           -Ambrose Bierce
 
============================================================================
====

On Mon, 23 Jul 2001, omid omoomi wrote:

> you mean this ?
> select count(*) from tablefoo;
> 
> 
> >From: Bhuvan A <bhuvansql@yahoo.com>
> >To: pgsql-sql@postgresql.org
> >Subject: [SQL] how can we get total records in pg server?
> >Date: Mon, 23 Jul 2001 20:03:42 +0530 (IST)
> >
> >
> >Hi all,
> >
> >how can we get the COUNT of total records in the db server?
> >
> >hope this could be simple for pg experts.
> >thankx in advance!
> >
> >Regards,
> >Bhuvaneswar.
>
>===========================================================================
=====
> >     Eighty percent of married men cheat in America.  The rest cheat in 
> >Europe.
> >                  -- Jackie Mason
>
>===========================================================================
=====
> >
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 3: if posting/reading through Usenet, please send an appropriate
> >subscribe-nomail command to majordomo@postgresql.org so that your
> >message can get through to the mailing list cleanly
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>