我是aws的新手,谁能告诉我redshifts与mysql命令的等价物是什么?
show tables -- redshift command
describe table_name -- redshift command
我是aws的新手,谁能告诉我redshifts与mysql命令的等价物是什么?
show tables -- redshift command
describe table_name -- redshift command
所有信息都可以在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;
我必须从信息模式中进行选择以获取我的表和列的详细信息;如果它可以帮助任何人:
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 命令行客户端工作
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
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.
捷径
\d 显示所有表格
\d 表名来描述表
\? 更多关于红移的快捷方式
在下面的文章中,我记录了从 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;
redshift now support show table
show table analytics.dw_users
您可以简单地使用下面的命令来描述一个表。
desc table-name
或者
desc schema-name.table-name