Amazon Redshift获取表的标识列列表

时间:2014-12-07 05:07:53

标签: amazon-redshift

如何获取Amazon Redshift中表格的标识列表? (使用系统表)

谢谢。

2 个答案:

答案 0 :(得分:3)

对于那些可能有兴趣了解如何获取Redshift数据库中的所有标识列的人。以下查询由Neil @ AWS发布到AWS Redshift论坛:

select 
    c.relname, 
    a.attname 
from pg_class c, pg_attribute a, pg_attrdef d 
where c.oid = a.attrelid 
    and c.relkind = 'r' 
    and a.attrelid = d.adrelid 
    and a.attnum = d.adnum 
    and d.adsrc like '%identity%' 
order by 1;

答案 1 :(得分:1)

PG_TABLE_DEF表包含有关表和列的信息:

select * from pg_table_def where tablename = 't2';
schemaname|tablename|column|  type   | encoding | distkey |sortkey| notnull 
----------+---------+------+---------+----------+---------+-------+---------
public    | t2      | c1   | bigint  | none     | t       |     0 | f
public    | t2      | c2   | integer | mostly16 | f       |     0 | f
public    | t2      | c3   | integer | none     | f       |     1 | t
public    | t2      | c4   | integer | none     | f       |     2 | f
(4 rows)

此外,Amazon Redshift用户可以访问标准的PostgreSQL目录表。有关PostgreSQL系统目录的更多信息,请参阅PostgreSQL System Tables