显示表格,描述相当于红移的表格

我是新来的aws,任何人都可以告诉我什么是红移等效于mysql命令?

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

所有的信息都可以在PG_TABLE_DEF表中find。

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

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

从名为table_name的表中描述所有列 – describe table等效的describe table

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

我不得不从信息模式中select我的表格和列的细节; 万一它帮助任何人:

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

或者干脆:

\dt来显示表格

\d+ <table name>来描述表格

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

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

Tomasz Tybulewicz的回答是很好的select。

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

如果架构名称未在searchpath中定义,则该查询将显示空的结果。 请先用下面的代码检查searchpath。

 SHOW SEARCH_PATH 

如果架构名称未在searchpath中定义,则可以重置searchpath。

 SET SEARCH_PATH to '$user', public, YOUR_SCEHMA_NAME 

在接下来的文章中,我logging了查询以检索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; 

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

 desc table-name 

要么

 desc schema-name.table-name