显示表,描述红移中等效的表

时间:2013-09-11 05:36:11

标签: amazon-web-services amazon-redshift

我是aws的新手,有人能告诉我什么是redshifts与mysql命令的等价物吗?

show tables -- redshift command
describe table_name -- redshift command

9 个答案:

答案 0 :(得分:96)

所有信息均可在PG_TABLE_DEFdocumentation中找到。

列出public架构中的所有表(默认) - 等效show tables

SELECT DISTINCT tablename
FROM pg_table_def
WHERE schemaname = 'public'
ORDER BY tablename;

来自名为 table_name - describe table等效表的所有列的说明:

SELECT *
FROM pg_table_def
WHERE tablename = 'table_name'
AND schemaname = 'public';

答案 1 :(得分:67)

我必须从信息模式中选择以获取我的表和列的详细信息;以防万一:

SELECT * FROM information_schema.tables
WHERE table_schema = 'myschema'; 

SELECT * FROM information_schema.columns
WHERE table_schema = 'myschema' AND table_name = 'mytable'; 

答案 2 :(得分:33)

或者简单地说:

\dt显示表格

\d+ <table name>来描述一个表

编辑:使用psql命令行客户端

工作

答案 3 :(得分:8)

Tomasz Tybulewicz回答是很好的方法。

SELECT * FROM pg_table_def WHERE tablename = 'YOUR_TABLE_NAME' AND schemaname = 'YOUR_SCHEMA_NAME';

如果未在搜索路径中定义架构名称,则该查询将显示空结果。 请首先通过以下代码检查搜索路径。

SHOW SEARCH_PATH

如果未在搜索路径中定义架构名称,则可以重置搜索路径。

SET SEARCH_PATH to '$user', public, YOUR_SCEHMA_NAME

答案 4 :(得分:1)

您可以使用--desc /查看Redshift中的视图/表定义。我一直使用Workbench / J作为Redshift的SQL客户端,它在“结果”选项卡旁边的“消息”选项卡中给出了定义。

答案 5 :(得分:0)

在下面的文章中,我记录了从Redshift中检索TABLE和COLUMN注释的查询。 https://sqlsylvia.wordpress.com/2017/04/29/redshift-comment-views-documenting-data/

享受!

表格评论

    SELECT n.nspname AS schema_name
     , pg_get_userbyid(c.relowner) AS table_owner
     , c.relname AS table_name
     , CASE WHEN c.relkind = 'v' THEN 'view' ELSE 'table' END 
       AS table_type
     , d.description AS table_description
     FROM pg_class As c
     LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
     LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
     LEFT JOIN pg_description As d 
          ON (d.objoid = c.oid AND d.objsubid = 0)
     WHERE c.relkind IN('r', 'v') AND d.description > ''
     ORDER BY n.nspname, c.relname ;

专栏评论

    SELECT n.nspname AS schema_name
     , pg_get_userbyid(c.relowner) AS table_owner
     , c.relname AS table_name
     , a.attname AS column_name
     , d.description AS column_description
    FROM pg_class AS c
    INNER JOIN pg_attribute As a ON c.oid = a.attrelid
    INNER JOIN pg_namespace n ON n.oid = c.relnamespace
    LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
    LEFT JOIN pg_description As d 
     ON (d.objoid = c.oid AND d.objsubid = a.attnum)
    WHERE c.relkind IN('r', 'v')
     AND a.attname NOT         
     IN ('cmax', 'oid', 'cmin', 'deletexid', 'ctid', 'tableoid','xmax', 'xmin', 'insertxid')
    ORDER BY n.nspname, c.relname, a.attname;

答案 6 :(得分:0)

快捷方式

\ d用于显示所有表格

\ d描述表的表名

\?有关redshift的更多快捷方式

答案 7 :(得分:0)

redshift 现在支持显示表

show table analytics.dw_users

https://forums.aws.amazon.com/ann.jspa?annID=8641

答案 8 :(得分:-3)

您只需使用以下命令来描述表格即可。

desc table-name

desc schema-name.table-name