You have a very aggravated person who demands you purge their email from any table you have in your system.
You have lots of tables that have email addresses. How do you find which tables have this person's email address.
Below is a handy plpgsql function we wrote that does the following. Given a search criteria, field name pattern, table_name pattern,
schema name pattern, data type pattern, and max length of field to check, it will search all fields in the database fitting those
patterns and return to you the names of these schema.table.field names that contain the search phrase.
To use the below you would do something like:
SELECT pc_search_tablefield('%john@hotmail%', '%email%', '%', '%', '%', null);
The above will return all database field names that have the phrase email in the field name and that contain the term john@hotmail
Every once in a while - particularly if you are using inherited tables, you forget to put an important index on one of your tables
which bogs down critical queries. Its sometimes convenient to inspect the index catalog to see what tables are missing indexes or
what tables are missing a critical index. Normally we try to stick with querying the information_schema because queries against that
schema work pretty much the same in PostgreSQL as they do in SQL Server and MySQL. For most of the examples below we had to delve into pg_catalog schema territory
since there was no view we could find in information_schema that would give us enough detail about indexes.