How to select a schema in postgres when using psql?

前端 未结 9 894
死守一世寂寞
死守一世寂寞 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:59

    In PostgreSQL the system determines which table is meant by following a search path, which is a list of schemas to look in.

    The first matching table in the search path is taken to be the one wanted, otherwise, if there is no match a error is raised, even if matching table names exist in other schemas in the database.

    To show the current search path you can use the following command:

    SHOW search_path;
    

    And to put the new schema in the path, you could use:

    SET search_path TO myschema;
    

    Or if you want multiple schemas:

    SET search_path TO myschema, public;
    

    Reference: https://www.postgresql.org/docs/current/static/ddl-schemas.html

提交回复
热议问题