Switching PostgreSQL database or Schema in DataGri

2019-05-23 14:58发布

问题:

Does anybody know how to switch between PostgreSQL databases or schemas in DataGrip (The Database IDE from JetBrains) in the console?

i can do that in Mysql by using:

Use my_database;

I tried using the Psql methods like

\connect

or

\c

but nothing works.

And could not find anyting in DataGrip Help page.

回答1:

If you speaking about the code, use SET search_path TO my_schema, public;

If you speaking about the tool, DataGrip, use switcher:



回答2:

  • Client: DataGrip
  • Database engine: PostgreSQL

To change the use of a database, you can do it by:

  • From the Terminal (IDE or SO) with psql
  • Through UI with pgAdmin4 (Query Tool) or IDE

Change the database through UI with the IDE

  1. You can delete the disused consoles as follows:

    1. Files (Right side panel of the IDE) >
    2. Scratches and Consoles >
    3. Database Consoles >
    4. Select the directory PostgreSQL - @localhost (Name of Project Data Source) >
    5. Delete disused consoles with right click and delete.
  2. Select a database to perform sql queries:

    1. Database (Left side panel of the IDE) >
    2. Double Click on PostgreSQL - @localhost >
    3. Double Click on the name of the database >
    4. Right click on public schema >
    5. New >
    6. Console

In this way in the directory Files> Scratches and Consoles > Database Consoles > PostgreSQL - @localhost, a new console positioned in said database was added.

  1. Finally, you can operate with DDL (create, alter, drop) or DML (insert, update, delete, select).

    CREATE TABLE test_2 (test int); TABLE test_2;

Quick tip: With the cursor positioned within the source code and ctrl+enter the sql queries are executed in the IDE.

GL