How to select a schema in postgres when using psql?

前端 未结 9 990
死守一世寂寞
死守一世寂寞 2021-01-29 18:11

I have a postgres database with multiple schemas. When I connect to the database from a shell with psql and I run \\dt it uses the default connection s

9条回答
  •  梦如初夏
    2021-01-29 18:52

    Use schema name with period in psql command to obtain information about this schema.

    Setup:

    test=# create schema test_schema;
    CREATE SCHEMA
    test=# create table test_schema.test_table (id int);
    CREATE TABLE
    test=# create table test_schema.test_table_2 (id int);
    CREATE TABLE
    

    Show list of relations in test_schema:

    test=# \dt test_schema.
                   List of relations
       Schema    |     Name     | Type  |  Owner   
    -------------+--------------+-------+----------
     test_schema | test_table   | table | postgres
     test_schema | test_table_2 | table | postgres
    (2 rows)
    

    Show test_schema.test_table definition:

    test=# \d test_schema.test_table
    Table "test_schema.test_table"
     Column |  Type   | Modifiers 
    --------+---------+-----------
     id     | integer | 
    

    Show all tables in test_schema:

    test=# \d test_schema.
    Table "test_schema.test_table"
     Column |  Type   | Modifiers 
    --------+---------+-----------
     id     | integer | 
    
    Table "test_schema.test_table_2"
     Column |  Type   | Modifiers 
    --------+---------+-----------
     id     | integer | 
    

    etc...

提交回复
热议问题