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
To view a list of all tables in a schema, you can query the PG_TABLE_DEF system catalog table. You can first examine the setting for search_path . The following example adds the SALES schema to the search path and shows all the tables in the SALES schema.
PG_TABLE_DEF is a table (actually a view) that contains metadata about the tables in a database. PG stands for Postgres, which Amazon Redshift was developed from. PG_TABLE_DEF is kind of like a directory for all of the data in your database.
Use SVV_EXTERNAL_TABLES to view details for external tables; for more information, see CREATE EXTERNAL SCHEMA. Use SVV_EXTERNAL_TABLES also for cross-database queries to view metadata on all tables on unconnected databases that users have access to. SVV_EXTERNAL_TABLES is visible to all users.
You can query the PG_TABLE_DEF system catalog view to view the definition of a table in Redshift database. SELECT * FROM pg_table_def WHERE tablename='your_table_name';
Many databases, Hive support SHOW TABLES commands to list all the tables available in the connected database or schema. Unfortunately, Redshift does not provide SHOW TABLES command. It has SHOW command, but it does not list tables.
As mentioned earlier, the Redshift SQL reference does not provide SHOW or DESCRIBE (DESC) SQL commands. You have to find alternative methods that allow you to list tables present in the database and provide the structure of a tables.
The ANALYZE command gets a sample of rows from the table, does some calculations, and saves resulting column statistics. By default, Amazon Redshift runs a sample pass for the DISTKEY column and another sample pass for all of the other columns in the table.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With