简体   繁体   English

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

[英]Show tables, describe tables equivalent in redshift

I'm new to aws, can anyone tell me what are redshifts' equivalents to mysql commands?我是 aws 的新手,谁能告诉我 redshifts 与 mysql 命令的等价物是什么?

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

All the information can be found in a PG_TABLE_DEF table, documentation .所有信息都可以在PG_TABLE_DEF文档中找到

Listing all tables in a public schema (default) - show tables equivalent:列出public模式中的所有表(默认) - show tables等效的show tables

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

Description of all the columns from a table called table_name - describe table equivalent:名为table_name的表中所有列的describe table - describe table等效:

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

Update:更新:

As pointed by @Kishan Pandey 's answer, if you are looking for details of a schema different by public , you need to set search_path to my_schema .正如@Kishan Pandey 的回答所指出的,如果您要查找与public不同的架构的详细信息,则需要set search_path to my_schema ( show search_path display current search path) ( show search_path显示当前搜索路径)

Listing tables in my_schema schema:列出my_schema模式中的表:

set search_path to my_schema;
select * from pg_table_def;

I had to select from the information schema to get details of my tables and columns;我必须从信息模式中进行选择才能获取我的表和列的详细信息; in case it helps anyone:如果它可以帮助任何人:

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

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

Or simply:或者干脆:

\\dt to show tables \\dt显示表格

\\d+ <table name> to describe a table \\d+ <table name>描述一个表

Edit: Works using the psql command line client编辑:使用 psql 命令行客户端工作

Tomasz Tybulewicz answer is good way to go. Tomasz Tybulewicz 的回答是个好方法。

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

If schema name is not defined in search path , that query will show empty result.如果搜索路径中未定义架构名称,则该查询将显示空结果。 Please first check search path by below code.请首先通过以下代码检查搜索路径。

SHOW SEARCH_PATH

If schema name is not defined in search path , you can reset search path.如果搜索路径中未定义架构名称,您可以重置搜索路径。

SET SEARCH_PATH to '$user', public, YOUR_SCEHMA_NAME

You can use - desc / to see the view/table definition in Redshift.您可以使用 - desc / 查看 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.我一直在使用 Workbench/J 作为 Redshift 的 SQL 客户端,它在“结果”选项卡旁边的“消息”选项卡中给出了定义。

In the following post, I documented queries to retrieve TABLE and COLUMN comments from Redshift.在下面的文章中,我记录了从 Redshift 检索 TABLE 和 COLUMN 注释的查询。 https://sqlsylvia.wordpress.com/2017/04/29/redshift-comment-views-documenting-data/ https://sqlsylvia.wordpress.com/2017/04/29/redshift-comment-views-documenting-data/

Enjoy!享受!

Table Comments表注释

    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 ;

Column Comments专栏评论

    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;

Shortcut捷径

\\d for show all tables \\d 显示所有表格

\\d tablename to describe table \\d 表名来描述表

\\? \\? for more shortcuts for redshift红移的更多快捷方式

redshift now support show table redshift 现在支持显示表

show table analytics.dw_users

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

You can simply use the command below to describe a table.您可以简单地使用下面的命令来描述一个表。

desc table-name

or要么

desc schema-name.table-name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM