Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show tables, describe tables equivalent in redshift

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 
like image 466
sk2 Avatar asked Sep 11 '13 05:09

sk2


People also ask

How do you see all the tables in Redshift?

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.

What is PG_TABLE_DEF?

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.

How do you view the Redshift spectrum table?

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.

How to view the definition of a table in Redshift database?

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

Does redshift support show Tables command in hive?

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.

Does redshift support DESC (DESC) SQL?

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.

How does the analyze command work in redshift?

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.


2 Answers

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; 
like image 99
Tomasz Tybulewicz Avatar answered Oct 13 '22 21:10

Tomasz Tybulewicz


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';  
like image 20
Alex Hinton Avatar answered Oct 13 '22 21:10

Alex Hinton