84

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

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

9 回答 9

118

所有信息都可以在PG_TABLE_DEF表格文档中找到。

列出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';

更新:

正如@Kishan Pandey 的回答所指出的那样,如果您正在寻找与 不同的架构的详细信息,则public需要set search_path to my_schema. (show search_path显示当前搜索路径)

列出my_schema架构中的表:

set search_path to my_schema;
select * from pg_table_def;
于 2013-09-11T11:37:41.830 回答
87

我必须从信息模式中进行选择以获取我的表和列的详细信息;如果它可以帮助任何人:

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

SELECT * FROM information_schema.columns
WHERE table_schema = 'myschema' AND table_name = 'mytable'; 
于 2015-01-07T16:56:24.377 回答
33

或者简单地说:

\dt显示表格

\d+ <table name>描述一张桌子

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

于 2013-09-12T22:54:48.093 回答
12

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
于 2017-06-16T10:20:14.527 回答
1

You can use - desc / to see the view/table definition in Redshift. I have been using Workbench/J as a SQL client for Redshift and it gives the definition in the Messages tab adjacent to Result tab.

于 2015-04-11T08:05:47.113 回答
1

捷径

\d 显示所有表格

\d 表名来描述表

\? 更多关于红移的快捷方式

于 2020-02-28T05:37:53.453 回答
1

在下面的文章中,我记录了从 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;
于 2017-04-29T16:02:20.923 回答
1

redshift now support show table

show table analytics.dw_users

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

于 2021-05-13T03:32:17.170 回答
-7

您可以简单地使用下面的命令来描述一个表。

desc table-name

或者

desc schema-name.table-name
于 2017-04-06T18:36:50.507 回答