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