Guest User

Untitled

a guest
Nov 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. -- CREATE A FUNCTION THAT RETURNS A COUNT FROM A GIVEN TABLE
  2. create or replace function
  3. count_conductor_rows(schema text, tablename text) returns integer
  4. as
  5. $body$
  6. declare
  7. result integer;
  8. query varchar;
  9. begin
  10. query := 'SELECT count(1) FROM ' || schema || '.' || tablename;
  11. execute query into result;
  12. return result;
  13. end;
  14. $body$
  15. language plpgsql;
  16.  
  17. -- GET ALL TABLES FROM CONDUCTOR SCHEMA AND CALL THE COUNT FUNCTION CREATED ABOVE.
  18. select
  19. table_name,
  20. count_conductor_rows(table_schema, table_name)
  21. from information_schema.tables
  22. where
  23. table_schema not in ('pg_catalog', 'information_schema')
  24. and table_type='BASE TABLE'
  25. order by 2 desc;
  26.  
  27. -- DELETE THE FUNCTION FROM THE DATABASE.
  28. --DROP FUNCTION count_conductor_rows(schema text, tablename text);
Add Comment
Please, Sign In to add comment