PostgreSQL in Visual Studio Code

How to use PostgreSQL in Visual Studio Code
Data Engineering
Python
Autor:in

Jan Kirenz

Veröffentlichungsdatum

22. Dezember 2021

In this tutorial, you will learn how to make SQL queries inside Visual Studio Code.

Prerequisites:

To be able to use your PostgreSQL database with Visual Studio Code, I recommend the PostgreSQL Management extension from Chris Kolkman.

After you have installed the extension and set up the database connection (see documentation), you can proceed as follows:

Step 1: In Visual Studio Code, use the keyboard shortcut:

and select PostgreSQL: New Query (this will open a blank file).

Step 2: Next, you need to select a Postgres Server (click on the icon Select Postgres Server) in the side bar (at the bottom) of the Visual Studio Code user interface. Select the server of your choice and choose the default database postgres.

Step 3: Now you could write SQL statements inside the blank file and run them (using the right mouse click).

Step 4: In Visual Studio Code click on the PostgreSQL Explorer (icon with an elephant) in the activity bar at the far left-hand side. Use your right mouse and click on refresh your database (in my case postgres) to see all tables.

Note: if you choose a Postgres server (Step 2) before you open a script (Step 1), you may get an error meassage: unable to select a connection - a document is not active. If this is the case, simply start with Step 1 and you should be fine.

PostgreSQL in VS Code