【发布时间】:2015-02-05 00:50:44
【问题描述】:
如何获取 Amazon Redshift 中表的身份列列表? (使用系统的表格)
谢谢。
【问题讨论】:
标签: amazon-redshift
如何获取 Amazon Redshift 中表的身份列列表? (使用系统的表格)
谢谢。
【问题讨论】:
标签: amazon-redshift
对于那些可能有兴趣了解如何获取 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;
【讨论】:
pg_attrdef中的列adsrc包含"identity(table_id) (column_index) (text_representation of identity)形式的身份信息。因此,对于第二列为 identity(1,1) 的表 (id=13123),它将是 "identity()"(13123), 1, '1,1'::text。
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。
【讨论】: