此查询按预期工作:
select nspname, relname, max(attnum) as num_cols
from pg_attribute a, pg_namespace n, pg_class c
where n.oid = c.relnamespace and a.attrelid = c.oid
and c.relname not like '%pkey'
and n.nspname not like 'pg%'
and n.nspname not like 'information%'
group by 1, 2
order by 1, 2;
nspname | relname | num_cols
--------+----------+----------
public | category | 4
public | date | 8
public | event | 6
public | listing | 8
public | sales | 10
public | users | 18
public | venue | 5
但是如何获取每个表的列列表? 预期产出:
nspname | relname | num_cols
--------+----------+----------
public | category | col1, col2, col3, col4
public | date | col1, col2, col3, col4 ..., col8
Mysql具有适用于此处的group_concat函数。
http://docs.aws.amazon.com/redshift/latest/dg/c_join_PG_examples.html
该页面上提到的以下查询不会为我返回任何行。
select distinct attrelid, rtrim(name), attname, typname
from pg_attribute a, pg_type t, stv_tbl_perm p
where t.oid=a.atttypid and a.attrelid=p.id
and a.attrelid between 100100 and 110000
and typname not in('oid','xid','tid','cid')
order by a.attrelid asc, typname, attname;
答案 0 :(得分:0)
确保在搜索路径中包含您要查看的所有模式。
http://docs.aws.amazon.com/redshift/latest/dg/r_search_path.html
set search_path to '$user', public, enterprise;
没有用户ID搜索路径中的架构的Redshift无法显示列。要访问表结构,您可能还希望对模式具有使用权限。