Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 选择包含特定列名的表_Postgresql - Fatal编程技术网

Postgresql 选择包含特定列名的表

Postgresql 选择包含特定列名的表,postgresql,Postgresql,我正在处理PostreSQL,我有这段代码从数据库中选择所有表及其列 选择t.table\u名称 ,数组_agg(c.column_name::text)作为列 来自信息\u schema.t表 连接信息\u schema.c列 在t.table\u name=c.table\u name上 其中t.table_schema='public' 和t.table_type='BASE table' 和c.table_schema='public' 团体 按t.表格名称; 我正试图修改它,以便只给

我正在处理PostreSQL,我有这段代码从数据库中选择所有表及其列

选择t.table\u名称
,数组_agg(c.column_name::text)作为列
来自信息\u schema.t表
连接信息\u schema.c列
在t.table\u name=c.table\u name上
其中t.table_schema='public'
和t.table_type='BASE table'
和c.table_schema='public'
团体
按t.表格名称;
我正试图修改它,以便只给我包含特定列名的表,例如“email” 问题是,当我添加另一个“and”时,它只返回一列而不是所有列

其中t.table_schema='public'和t.table_type='BASE table'和c.table_schema='public'和c.column_name='email'
使用having子句:

select t.table_name
     , array_agg(c.column_name::text) as columns
  from information_schema.tables t 
  join information_schema.columns c 
    on t.table_name = c.table_name
   and t.table_schema = c.table_schema
 where t.table_schema = 'public' 
   and t.table_type = 'BASE TABLE' 
 group by t.table_name
 having 'email' = any(array_agg(c.column_name::text))
如果要检查多个列,可以这样做:

select t.table_name
     , array_agg(c.column_name::text) as columns
  from information_schema.tables t 
  join information_schema.columns c 
    on t.table_name = c.table_name
   and t.table_schema = c.table_schema
 where t.table_schema = 'public' 
   and t.table_type = 'BASE TABLE' 
 group by t.table_name
 having array_agg(c.column_name::text) @> array['email', 'phone']