PostgreSQL:在数据库的所有表中搜索名为 LIKE *active* 的字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21728073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:18:33  来源:igfitidea点击:

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

postgresqlpostgresql-9.1pgadmin

提问by Max Muster

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

在我的公共模式中,我有 1200 个表。在一张或多张表中的某个地方,有一些字段称为 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?

我想在控制台中使用 PGAdmin 或通过控制台上的普通客户端找到它们,我怎么能用更少的资源快速地做到这一点?

回答by murison

Try:

尝试:

SELECT * 
FROM information_schema.columns 
WHERE TRUE
AND table_schema = 'public'
AND column_name ~* 'active'

回答by Houari

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%'

回答by uniquegino

select * from INFORMATION_SCHEMA.COLUMNS 
where TABLE_SCHEMA like '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 serach for a COLUMN