CREATE OR REPLACE FUNCTION totalRecords()
RETURNS integer as $total$
DECLARE
total integer := 0;
perCount integer := 0;
result RECORD;
name RECORD;
tables varchar;
getCount varchar;
BEGIN
tables := 'select tablename from pg_tables where schemaname = ''public''';
FOR name IN EXECUTE tables LOOP
getCount := 'select count(*) from ' || name.tablename;
FOR result IN EXECUTE getCount LOOP
RAISE NOTICE '%:%',name,result.count;
total = total + result.count;
END LOOP;
END LOOP;
RAISE NOTICE 'totalSum: %',total;
RETURN total;
END;
$total$ LANGUAGE plpgsql;