Work with SQL cells
DataSpell allows you to use SQL cells to query databases, dataframes and attached CSV files in Jupyter notebooks and automatically save query results to pandas dataframes.
Enable the Database Tools and SQL plugin
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in DataSpell by default. If the relevant features are not available, make sure that you did not disable the plugin.
Press Ctrl+Alt+S to open settings and then select
.Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
Query a database
Select SQL in the cell type selector in the notebook toolbar.
Select the data source from the list of connected data sources:
To add a new data source, follow the steps below:
- Add new data source
Open the Database tool window by clicking Database or go to in the main menu.
Do one of the following:
Click New in the Database tool window.
Press Alt+Insert.
Select Data Source and choose the database type.
Configure the connection settings in the Data Sources and Drivers dialog.
To query a dataframe or CSV file, select DataFrame:
Set the name of the variable in which the result of the SQL request will be stored as a dataframe.
Enter the SQL statement and execute it by running the SQL cell.
To run the SQL cell, do one of the following:
Right-click on the SQL cell and select Run cell from the context menu.
Press Ctrl+Enter.
The query result will be shown in the output and saved to the dataframe.
Continue to work with the SQL variable in the code cells.