---
description: Immerse SQL Editor
---

# SQL Editor

Heavy Immerse includes an SQL Editor that you can use to build and run SQL queries. The SQL Editor includes an input box, query results box, a searchable table browser, and query history that you can use to create queries, run them, and see the results.

![](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HC6j6Bt2AU_FSffph%2F-M8HChg6WP8UdKOOp0uX%2F3_sql_editor.png?alt=media\&token=a478db0e-4372-4b77-b535-4c60d10982f1)

## &#x20;Input Box

Create an SQL query by clicking in the input box and typing SQL code, or by using the table browser. The following features make it easier to create queries:

* Autocomplete - When typing an SQL query, use the Tab key to speed code entry and avoid misspellings:
  * Complete a command that you have started typing. For example, if you type `SE`, pressing the Tab key completes the `SELECT` command.
  * Show a drop-down list of available commands or table or column names, contextual to the location of the cursor.
* Color coding - The SQL Editor highlights reserved words to make the code easier to read.
*   Format SQL - Format and indent strings of SQL code to make it easy to read. For example, if you click **Format SQL** for the query in the input window shown above, the code looks like this:\


    ![format\_sql.png](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HC6j6Bt2AU_FSffph%2F-M8HCorSIYa_3_Ba1hhr%2F3_format_sql.png?alt=media\&token=1e1d76d6-2c87-406e-97d7-6a3f72df5c0e)
*   Run query / Run selected - Clicking Run query shows the output of the query in the results window below the input window.\


    You can also run just part of the code in the input window. If you want to run part of a query, or have multiple queries in the input box and want to select one to run, highlight the code you want to run and click **Run selected**:



![run\_selected.png](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HCrTJLpt9FyVUNWtI%2F-M8HD2VQAiAxR7Qbbofb%2F3_run_selected.png?alt=media\&token=424cbe1d-8840-4757-bb6f-bf97bdbda63d)

{% hint style="info" %}
You can also use CTRL+ENTER or command+return to run the query or the selected portion of the query.
{% endhint %}

## Table Browser

Use the Table Browser to find available tables and columns and use them to build your queries. It also provides snippets of common queries that you can add to your code. Hovering over a table, column, or query snippet reveals the Copy to SQL Input Box icon; click to add the table name, column name, or code snippet to your query:

![](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HCrTJLpt9FyVUNWtI%2F-M8HDINWrR02SDTbQkow%2F3_copy_to_input.png?alt=media\&token=0c8398be-b1f9-4ce4-a07e-918e2111006d)

When you open the SQL Editor, the Table Browser shows the complete list of tables available.

* Use Find a table to refine your search. For example, typing **trees** in the search box narrows the results to tables that include "trees" in the name.
*   Select a table (in this case, nyc\_yellow\_taxi\_2014) to see the columns in the table. You can use the Data Type Filters to narrow columns by Number, Date/Time, or Categorical data types:

    ![table\_browswer\_columns.png](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HCrTJLpt9FyVUNWtI%2F-M8HDPhlVhFvrzt1xNIE%2F3_table_browser_columns.png?alt=media\&token=4e2811a2-b550-48da-a0e2-3f03a8c5be7c)
*   Each table and column has predefined _query snippets_ associated with it. These snippets are shortcuts to commonly run queries. For example, the table column vendor\_id in the TaxiDemo table has the following predefined queries:

    ![query\_snippet.png](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HCrTJLpt9FyVUNWtI%2F-M8HDmBHYcEXNPWtOngQ%2F3_query_snippet.png?alt=media\&token=5bd6913a-5453-4cb6-a226-c2f048ada577)
*   Click the **Query history** tab to see to see the list of previously run queries. You can click the Insert... icon to add the query to the input box, or click the query to show the previously fetched results.



![query\_history.png](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-M8HCrTJLpt9FyVUNWtI%2F-M8HDvVfZZGueCjRHWnm%2F3_query_history.png?alt=media\&token=99a1ee79-252f-4667-8319-f81eeddb36d7)

## Running Vega JSON in SQL Editor

You can render images in the SQL editor by pasting Vega JSON code in the editor and running it.

If the Vega code that you add to the SQL Editor is valid, the Format SQL button changes to Format JSON.&#x20;

![](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-MG5UscgiNawaZtrvLuS%2F-MG5W7hWIp5RdvOP8RCy%2F3_sql-editor-3.png?alt=media\&token=9d070a35-6b72-45e8-b4d9-840cab43942c)

Click **Run query** to render the Vega code and display the PNG image in the tabular results window.

![](https://3405598576-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6kHkWH17KJKscL0Cc4%2F-MG5UscgiNawaZtrvLuS%2F-MG5WCjhcMaUoMGzuhLe%2F3_sql-editor-4.png?alt=media\&token=4e956011-c978-41a6-a69e-6f136a03f6d3)

As with SQL queries, render queries are added to the Query history.
