Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Search all tables of a database for a field called LIKE *active*

In my public schema I have 1200 tables. Somewhere in one or more of this tables there are some fields called LIKE "active" like: - status_active - hr_active - who_knows_what_active_could_be

I want to find them all using PGAdmin in the console or via the normal client on console how could I do this with quick with less resources?

like image 525
Max Muster Avatar asked Feb 12 '14 12:02

Max Muster


People also ask

What is difference between Pg_catalog and Information_schema?

All system tables and views in the pg_catalog schema (including pg_tables ) are completely Postgres specific. Queries using those will never run on other DBMS products. The INFORMATION_SCHEMA views use those system views and tables to collect and present the metadata as required by the SQL standard.


3 Answers

Try:

SELECT * 
FROM information_schema.columns 
WHERE TRUE
AND table_schema = 'public'
AND column_name ~* 'active'
like image 185
murison Avatar answered Oct 22 '22 03:10

murison


You can try:

SELECT table_name,tables.table_catalog,tables.table_schema,column_name
FROM information_schema.columns
inner join information_schema.tables
using(table_name,table_schema)
WHERE  table_type = 'BASE TABLE'
  and column_name ilike '%active%'
like image 26
Houari Avatar answered Oct 22 '22 03:10

Houari


select * from INFORMATION_SCHEMA.COLUMNS 
where TABLE_SCHEMA = 'your schema name'
--and TABLE_NAME ilike '%your keyword%' --when you need to search for a TABLE
and COLUMN_NAME ilike '%your keyword%' --when you need to search for a COLUMN
like image 35
uniquegino Avatar answered Oct 22 '22 01:10

uniquegino