Show tables, describe tables equivalent in redshift

后端 未结 8 780
说谎
说谎 2021-01-30 03:17

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
<         


        
相关标签:
8条回答
  • 2021-01-30 03:21

    Shortcut

    \d for show all tables

    \d tablename to describe table

    \? for more shortcuts for redshift

    0 讨论(0)
  • 2021-01-30 03:35

    You can simply use the command below to describe a table.

    desc table-name
    

    or

    desc schema-name.table-name
    
    0 讨论(0)
  • 2021-01-30 03:39

    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';
    
    0 讨论(0)
  • 2021-01-30 03:40

    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'; 
    
    0 讨论(0)
  • 2021-01-30 03:43

    Or simply:

    \dt to show tables

    \d+ <table name> to describe a table

    Edit: Works using the psql command line client

    0 讨论(0)
  • 2021-01-30 03:43

    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
    
    0 讨论(0)
提交回复
热议问题