Query consoles
Enable the Database Tools and SQL plugin
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in GoLand by default. If the relevant features aren't available, make sure that you didn't disable the plugin.
Press Control+Alt+S to open the IDE settings and then select
.Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
Overview
Query or database consoles are SQL files that are attached to a data source. You can write and execute SQL statements in query consoles the same way as you do it in terminal.
When you create a data source, the data source's default query console is created automatically. If necessary, you can create additional query consoles.
Each console creates a new connection session. If you do not want to create new connections, enable single session mode.
All the created query consoles are located in the internal Database Consoles directory. To open this folder, open the Project tool window (Alt+1) and navigate to . On your machine, the query console files are stored in the consoles subdirectory of the IDE configuration directory.
For more information about working with query results in query consoles, refer to Query results.
Database connection session
For each console, a database connection session is created automatically. You can create new connection sessions and attach your console to existing ones in the console toolbar.
In the following example, the PostgreSQL console is associated with the guest.public
schema of a data source and connected to it via the console
connection session. You can change the console
session to actor
or create a new session and attach the console to it.
Code editor
The code editor is where you compose your SQL statements using the resolve modes and coding assistance features, and execute them against the associated data source.
Find the code editor toolbar controls in Code editor controls. Read more about the editor in Editor basics.
SQL statement execution
When you execute a statement, the Services tool window opens. The Services tool window displays available connection sessions, Output and Result tabs. For more information about the Services tool windows, refer to Services tool window.
If the executed statement retrieves data (for example,
SELECT
), results are displayed in the Result tab that has a title of a qualified table name. For more information about creating custom titles for result tabs, refer to Use custom titles for tabs with results.If the executed statement does not retrieve data, results are displayed in the Output tab.
Code editor.
Services tool window.
Code editor.
Services tool window.
Output and Result tabs. Output tab is active.
Right toolbar of the Output tab.
Work with console files
Create a query console
To create a console, use one of the following actions in the Database tool window ( ).
Click a data source and select
.Right-click a data source and select
.Click a data source, press Alt+Insert, and select Query Console.
Click a data source, press Control+Shift+F10, and select New Query Console.
Click a data source and press Control+Shift+Q.
Open a console
When a console is open, you can write SQL here, run it and get the result.
In the Project tool window ( ) , navigate to , double-click a console file.
In the Database tool window ( ) , click the Jump to Query Console… button () and select a console that you want to open or create a new one.
Click a data source, press F4, and select the console that you need.
Rename a query console
To rename a query console file, do one of the following:
Right-click a console tab, and select Rename File.
Open the Project tool window ( ) and navigate to . Expand a data source group that includes your console, right-click the console file, and select (Shift+F6).
Group consoles under the data source directory
In the Project tool window ( ) , navigate to .
Right-click a data source group where you want to create a new directory, select
.Specify a name of the directory.
Select and drag console files to the directory.
In the Move dialog, click Refactor.
Delete a query console
In the Project tool window ( ) , navigate to .
Expand a data source group that includes your console.
Right-click a console file and select Delete.
Copy a console file to a new location
In the Project tool window ( ) , navigate to .
Expand a data source group that includes your console.
Right-click a console file and select
.In the To directory field, specify a new location for the file.
Save a console as a file
In the query console file tab, press Control+Shift+S.
In the To directory field, specify the location where you want to store the file.
Open a console file in the file browser
To open a console file in your file browser, do one of the following:
Right-click a console tab and navigate to
.Open the Project tool window ( ) and navigate to . Expand a data source group that includes your console, right-click the console file, and select .
Configure console settings
Change a schema
In the query console toolbar, open the list of databases and schemas by clicking the <schema> button and select the one that you want to run queries against.
For more information about schemas, refer to Schemas.
Modify console settings
Open a console and click the Open Query Execution Settings... button ().
Configure console dialects
Change the SQL dialect in the code editor
Right-click the editing area and select Change Dialect (<current_dialect>) to. In the Change SQL Dialect window, select a dialect.
Productivity tips
View history of a query console
In a console, right-click any area and select
.
Apply a code style in the editor
Right-click any area or a selection of code in the editor and select Reformat Code. Alternatively, press Control+Alt+L.
View the file path of a query console
To see the details of a file, hover over the console tab.
Navigate to a console file from the Select In window
Press Alt+F1, select Project View and press Enter.
Edit data in INSERT statements as a table
Select
INSERT
statements that you want to edit.Right-click the selection and click Edit as Table.
In the table editor that opens, make necessary changes in the table cell. Press Enter to confirm.
Context menu
In the code editor context menu, use the following actions to increase your productivity:
Action | Shortcut | Description |
---|---|---|
Edit as Table | In | |
Change Dialect (<CurrentDialect>) | Change the SQL dialect. Select a dialect from the list. | |
Explain Plan |
| |
Execute | Control+Enter | Execute the current statement or the sequence of selected statements. |
Execute to File | Execute the current statement and save results in a text file. Select the output format and specify the file location and name. | |
Run 'console [data_source]' | Control+Shift+F10 | Execute all the statements in the query console. |
Query console reference
Use the code editor to compose and execute your SQL statements as well as to perform other associated tasks.
Read more about the editor in Editor basics.
Toolbar controls
Icon | Action and shortcut | Description |
---|---|---|
Execute Control+Enter | Execute selected SQL statement or statements. If nothing is selected, the current statement is executed. | |
Browse Query History Control+Alt+E | Open a dialog that shows all the statements that you have run for the corresponding data source. See also, Use the Query History dialog. | |
View Parameters | Open or close the Parameters dialog. | |
Open Query Execution Settings… | Open the Settings dialog to view or edit the query execution settings. section of theFor more information about these settings, refer to Query Execution. | |
Transaction Mode and Transaction Isolation | Select the isolation level for database transactions and the way the transactions are committed.
For more information about database transaction modes and isolation, refer to Submit changes to a database. | |
Commit | (For the Manual transaction mode.) Commit the current transaction. This button is available only for the manual transaction mode. See also, transaction mode and isolation. | |
| Roll back | (For the Manual transaction mode.) Roll back changes. This button is available only for the manual transaction mode. See also, transaction modes and isolation. |
Cancel Running Statements Control+F2 | Terminate execution of the current statement or statements. | |
File Resolve Mode | Select the resolve mode to manage the context that database objects in your code are resolved to.
For more information about the resolve modes, refer to Resolve modes. In the following video, the Once the resolve mode is changed to Script, the second | |
In-Editor Results | Toggle the display of query result within the code editor of query console. For more information about the in-editor results, refer to In-Editor Results. | |
<schema> | Switch current schema | Select the default schema or database. For PostgreSQL, Amazon Redshift, and Greenplum use the <schema> list to form the schema search path. For more information about schemas, refer to Schemas. |
<session> | Switch attached session | Select the database connection session. For more information about the database connection sessions, refer to Managing connection sessions |