Information_Schema的Redshift选项

时间:2013-07-12 17:29:09

标签: sql ssms information-schema amazon-redshift

刚从SSMS迁移到Redshift(使用DBeaver),我想知道是否有一个很好的选项来获取表格描述。在SQL服务器中,您可以针对information_schema编写一个很好的查询来提取列名,数据类型等.Redshift中的任何类似选项?

2 个答案:

答案 0 :(得分:2)

在Redshift中可以使用INFORMATION_SCHEMA表。

可能是您选择的查询工具(DBeaver)正在GUI中隐藏架构。但是,您仍然可以正常查询它们。

当我使用Navicat时,我肯定会这样。如果要查看架构,则在使用SQL Workbench或SQuirreL时可以看到它。

2016-04-04:AWS创建了一个更简单的视图,提供完整的CREATE TABLE语句,包括所有Redshift特定内容。从这里获取它们:https://github.com/awslabs/amazon-redshift-utils/tree/master/src/AdminViews

答案 1 :(得分:1)

看起来你正在寻找这样的东西:http://rocky-says.blogspot.com/2015/01/amazon-redshift-generate-table-ddl.html

以下是可以帮助您的查询:只需替换<表>和< SCHEMA>使用您的表名和Schema

SELECT DISTINCT n.nspname AS schemaname
 ,c.relname AS tablename
 ,a.attname AS COLUMN
 ,a.attnum AS column_position
 ,pg_catalog.format_type(a.atttypid, a.atttypmod) AS TYPE
 ,pg_catalog.format_encoding(a.attencodingtype) AS encoding
  ,a.attisdistkey AS distkey
 ,a.attsortkeyord AS sortkey
 ,a.attnotnull AS notnull
 ,a.attencodingtype AS compression
 ,con.conkey AS primary_key_column_ids
 ,con.contype AS con_type
FROM pg_catalog.pg_namespace n
 ,pg_catalog.pg_class c
 ,pg_catalog.pg_attribute a
 ,pg_constraint con
 ,pg_catalog.pg_stats stats
WHERE n.oid = c.relnamespace
 AND c.oid = a.attrelid
 AND a.attnum > 0
 AND c.relname NOT LIKE '%pkey'
 AND lower(c.relname) = ''
 AND n.nspname = ''
 AND c.oid = con.conrelid(+)
ORDER BY A.ATTNUM
;