Skip site navigation (1) Skip section navigation (2)

counting records of schema

From: <Tom(dot)Zschockelt(at)flender(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: counting records of schema
Date: 2004-10-26 06:03:26
Message-ID: OFD124C5A0.B2424868-ONC1256F39.0020D016-C1256F39.00214C17@flender.com (view raw or flat)
Thread:
Lists: pgsql-general
hi,

I need to know how many records are in a specific schema of a database.

I've tried with a function but there are still problems 

Can you give me some hints :

-- Function: count_records(myschema varchar)

-- DROP FUNCTION count_records("varchar");

CREATE OR REPLACE FUNCTION count_records("varchar")
  RETURNS int8 AS
$BODY$DECLARE
 anzahl bigint := 0;
 summe bigint := 0;
 ds RECORD;
 tabellenname varchar(100);
BEGIN
 FOR ds IN select * from pg_tables where schemaname = myschema LOOP

  tabellenname := quote_ident(ds.schemaname) || '.' || 
quote_ident(ds.tablename);
  EXECUTE 'SELECT count(*) FROM ' || tabellenname INTO 
quote_ident(anzahl); 
  summe := summe + anzahl;
 END LOOP;
 return summe;
END;$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION count_records("varchar") OWNER TO postgres;

best regards

tom

Responses

pgsql-general by date

Next:From: Adrian MaierDate: 2004-10-26 06:13:54
Subject: Re: [HACKERS] Question on the 8.0Beta Version
Previous:From: Deepa KDate: 2004-10-26 05:00:32
Subject: [Fwd: Abrupt close of pgsql backend]

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group