【问题标题】:How do we get all columns which are the part of sortkey in Redshift我们如何在 Redshift 中获取属于 sortkey 的所有列
【发布时间】:2016-12-24 06:53:49
【问题描述】:

我需要获取所有列,它们是 Redshift 中 sortkey 的一部分。

我尝试使用“select * from svv_table_info”获取信息,但它只有一列的信息。你能告诉我,我如何获取作为表格 Sortkey 一部分的所有列。

谢谢, 桑吉夫

【问题讨论】:

    标签: amazon-redshift


    【解决方案1】:

    感谢大家的帮助。我已经尝试使用“pg_table_def”表来获取 sortkey 和 distkey 信息,但我只看到了 pg_catalog 和 Public 架构,我刚刚浏览了 Amazon 开发人员指南,发现我们需要使用以下命令将架构添加到搜索路径:- 显示搜索路径; 将 search_path 设置为 '$user', 'public', 'NewSchema';

    在搜索路径中添加“NewSchema”后,我可以在 pg_table_def 中看到此模式的 sortkey 和 distkey 信息

    谢谢, 桑吉夫

    【讨论】:

      【解决方案2】:

      桑吉夫,

      名为 pg_table_def 的表包含有关列的信息。

      在下面的示例中,我创建了一个包含四列的简单表,并使用其中两列作为排序键。

      正如您在我的查询结果中看到的,如果列是排序键的一部分,“排序键”字段会显示非 0 的数字。

      dev=# drop table tb1;
      DROP TABLE
      dev=# create table tb1 (col1 integer, col2 integer, col3 integer, col4 integer) distkey(col1) sortkey(col2, col4);
      CREATE TABLE
      dev=# select * from pg_table_def where tablename = 'tb1';
       schemaname | tablename | column |  type   | encoding | distkey | sortkey | notnull 
      ------------+-----------+--------+---------+----------+---------+---------+---------
       public     | tb1       | col1   | integer | none     | t       |       0 | f
       public     | tb1       | col2   | integer | none     | f       |       1 | f
       public     | tb1       | col3   | integer | none     | f       |       0 | f
       public     | tb1       | col4   | integer | none     | f       |       2 | f
      (4 rows)
      

      【讨论】:

        【解决方案3】:

        怎么样:

        select "column", type, encoding, distkey, sortkey, "notnull" 
        from pg_table_def
        where tablename = 'YOURTABLE' 
        and sortkey <> 0;
        

        【讨论】:

        • 感谢大家的帮助。我已经尝试使用 pg_table_def 表来获取 sortkey 和 distkey 信息,但我只看到了 pg_catalog 和 Public 架构,我刚刚浏览了 Amazone 开发人员指南,发现我们需要使用以下命令将架构添加到搜索路径。
        猜你喜欢
        • 2018-02-04
        • 1970-01-01
        • 2019-03-08
        • 2019-05-23
        • 2012-06-09
        • 2016-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多