9

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.

Hamza Benzaoui
  • 168
  • 3
  • 14

2 Answers2

8

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

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

enter image description here

moscas
  • 9,064
  • 36
  • 42
  • Yeah i meant the code, `SET search_path TO my_schema, public;` wont switch databases, in it shows that Database Console down it shows that: **sql> SET SEARCH_PATH TO MY_DATABASE, public** But the code console above still use the same database i mean if i tried to query another database i still get the error : _cross-database references are not implemented_ – Hamza Benzaoui Feb 21 '18 at 14:51
  • Can you please share a screenshot with that error in DataGrip? – moscas Feb 22 '18 at 13:54
  • don't have a screenshot I can share, but I can confirm that in a console in datagrip the search path command completes without error, but also without changing the context that the session is connected to – simon coleman Sep 20 '22 at 14:52
  • Do you see the set search_path statement in the Servics window? – moscas Sep 22 '22 at 13:36
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

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62