【问题标题】:Amazon Redshift get list of identity columns for a tableAmazon Redshift 获取表的身份列列表
【发布时间】:2015-02-05 00:50:44
【问题描述】:

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

谢谢。

【问题讨论】:

    标签: amazon-redshift


    【解决方案1】:

    对于那些可能有兴趣了解如何获取 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
    【解决方案2】:

    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

    【讨论】:

    • 感谢您的回答,但此表未提供有关“身份”列的任何信息。必须有一个包含此信息的系统表,但我仍然找不到它。
    • “身份”列是什么意思?主键?
    • 它们是 RedShift 中的自动递增列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多