I'm new to aws, can anyone tell me what are redshifts' equivalents to mysql commands?
show tables -- redshift command
describe table_name -- redshift command
I'm new to aws, can anyone tell me what are redshifts' equivalents to mysql commands?
show tables -- redshift command
describe table_name -- redshift command
All the information can be found in a PG_TABLE_DEF table, documentation.
Listing all tables in a public schema (default) - show tables equivalent:
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:
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. (show search_path display current search path)
Listing tables in my_schema 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
\d+ <table name> to describe a table 
Edit: Works using the psql command line client
 
    
    Tomasz Tybulewicz answer is good way to go.
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
 
    
    Redshift provides system tables and views which are simpler to use than the postgres default pg_catalog and information_schema tables. You can find the list of tables here
To get list of tables in a schema, you can query SVV_ALL_TABLES / SVV_REDSHIFT_TABLES
    select * from SVV_REDSHIFT_TABLES where schema_name = '<<schema_name>>';
To get table definition including is sort key and distribution key, you can query SVV_REDSHIFT_COLUMNS
    select * from SVV_REDSHIFT_COLUMNS where schema_name = '<<schema_name>>' and table_name = '<<table_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.
In the following post, I documented queries to retrieve TABLE and COLUMN comments from Redshift. 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 tablename to describe table
\? for more shortcuts for redshift
 
    
    You can simply use the command below to describe a table.
desc table-name
or
desc schema-name.table-name
 
    
    