DataSpell 2024.1 Help

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 aren't available, make sure that you didn't disable the plugin.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Plugins.

  2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

Query a database

  1. Select SQL in the cell type selector in the notebook toolbar.

    Select SQL cell
  2. Select the data source from the list of connected data sources:

    Select data source

    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 Window | Tool Windows | Database in the main menu.

      Database tool window opened
    • Do one of the following:

      • Click New in the Database tool window.

      • Press Alt+Insert.

    • Select Data Source and choose the database type.

      Select data source
    • Configure the connection settings in the Data Sources and Drivers dialog.

      Configure the data source settings

    To query a dataframe or CSV file, select DataFrame:

    Select DataFrame as a data source
  3. Set the name of the variable in which the result of the SQL request will be stored as a dataframe.

    Set python variable
  4. 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.

    Query results displayed in dataframes
  5. Continue to work with the SQL variable in the code cells.

    Continue to work with SQl variable
Last modified: 29 March 2024