Sql 用于在红移中查找具有特定值的单元格的脚本
我有一个疑问:Sql 用于在红移中查找具有特定值的单元格的脚本,sql,amazon-redshift,Sql,Amazon Redshift,我有一个疑问: select t.table_schema, t.table_name, c.column_name from information_schema.tables t inner join information_schema.columns c on c.table_name = t.table_name and c.table_schema = t.table_schema where c.col
select t.table_schema,
t.table_name,
c.column_name
from information_schema.tables t
inner join information_schema.columns c
on c.table_name = t.table_name
and c.table_schema = t.table_schema
where c.column_name like '%column_name%'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
order by t.table_schema;
是否有什么地方我可以搜索特定的值,并查看它属于哪个列、表和模式
比如说,,
我想搜索一个值“WINNER”,并找出哪些列包含这个值(显然还有表和模式)
该列可能是带有value WINNER的STATUS,以及表CUSTOMER和schema ALL_数据下的STATUS
有人能帮忙吗?没有直接的方法可以做到这一点,据我所知,任何DBMS中都没有内置功能。一种方法是创建SQL,它选择所有类似文本的列并生成另一个SQL。有一个例子:
select 'select '''||t.table_schema||''' as table_schema, '''||
t.table_name||''' as table_name, '''||
c.column_name||''' as column_name,'||
' count(*) as occurrences'
' from '||t.table_schema||'.'||t.table_name||
' where '||c.column_name||' like ''WINNER'''
||' union all '
from information_schema.tables t
inner join information_schema.columns c
on c.table_name = t.table_name
and c.table_schema = t.table_schema
where c.column_name like '%column_name%'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
and c.data_type = 'character varying'
order by t.table_schema;
根据查询中设置的限制,它将生成和您要搜索的列一样多的行。在客户端复制此结果块(从最后一行中删除“全部联合”)
然后执行。尽量限制行数以获得更好的性能。由于列式数据存储Redshift将非常有效地执行此操作,请记住,这种方法的面向行DBMS性能会差得多。没有直接的方法可以做到这一点,据我所知,任何DBMS中都没有内置功能。一种方法是创建SQL,它选择所有类似文本的列并生成另一个SQL。有一个例子:
select 'select '''||t.table_schema||''' as table_schema, '''||
t.table_name||''' as table_name, '''||
c.column_name||''' as column_name,'||
' count(*) as occurrences'
' from '||t.table_schema||'.'||t.table_name||
' where '||c.column_name||' like ''WINNER'''
||' union all '
from information_schema.tables t
inner join information_schema.columns c
on c.table_name = t.table_name
and c.table_schema = t.table_schema
where c.column_name like '%column_name%'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
and c.data_type = 'character varying'
order by t.table_schema;
根据查询中设置的限制,它将生成和您要搜索的列一样多的行。在客户端复制此结果块(从最后一行中删除“全部联合”)
然后执行。尽量限制行数以获得更好的性能。由于列式数据存储Redshift将非常有效地执行此操作,请记住,这种方法的面向行DBMS性能将更差。您需要在Redshift之外处理此脚本。e、 您需要在红移之外处理此脚本。e、 g.python。