Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CREATE A FUNCTION THAT RETURNS A COUNT FROM A GIVEN TABLE
- create or replace function
- count_conductor_rows(schema text, tablename text) returns integer
- as
- $body$
- declare
- result integer;
- query varchar;
- begin
- query := 'SELECT count(1) FROM ' || schema || '.' || tablename;
- execute query into result;
- return result;
- end;
- $body$
- language plpgsql;
- -- GET ALL TABLES FROM CONDUCTOR SCHEMA AND CALL THE COUNT FUNCTION CREATED ABOVE.
- select
- table_name,
- count_conductor_rows(table_schema, table_name)
- from information_schema.tables
- where
- table_schema not in ('pg_catalog', 'information_schema')
- and table_type='BASE TABLE'
- order by 2 desc;
- -- DELETE THE FUNCTION FROM THE DATABASE.
- --DROP FUNCTION count_conductor_rows(schema text, tablename text);
Add Comment
Please, Sign In to add comment