Snowflake Extension for Visual Studio Code

Snowflake provides an extension for Visual Studio Code (VS Code) to enable Snowflake users to write and execute Snowflake SQL statements directly in VS Code. The extension also integrates with Snowpark Python to provide debugging, syntax highlighting, and autocomplete features for SQL in Python code.

Extensions are pre-packaged functionality, often provided by third parties, which add new features and functionality to VS Code.

Installing the Snowflake Extension for Visual Studio Code

Snowflake users can install the VS Code extension directly from the Visual Studio marketplace, or download the extension, packaged as a .xsix file, and then install.

Installing from the Visual Studio Marketplace

To install directly from the Visual Studio Marketplace, do the following:

  1. Open Visual Studio Code.

  2. Select Code » Preferences » Extensions.

    You can also select View » Extensions or click the extensions button Extensions button in the VS Code Activity Bar.

  3. In the Search Extensions text box, enter the text Snowflake to search for the Snowflake Visual Studio Extension.

  4. From the set of extensions, select the extension authored by Snowflake and click Install.

Installing from a .vsix file

To download and install from a .vsix file, do the following:

  1. Download the extension.

    1. Open the page Snowflake Visual Studio Code extension.

    2. Select the Version History tab.

    3. Select a version to download and click Download. Note where the file is downloaded.

  2. Open Visual Studio Code.

  3. Select Code » Preferences » Extensions.

    You can also select View » Extensions or click the extensions button Extensions button in the Activity Bar.

  4. Select Install from VSIX from the more(…) menu.

  1. Locate the snowflake-x.y.z.vsix file on your computer, select the file, and then select Install.

After the installation completes, the Snowflake Extension for Visual Studio Code appears in the INSTALLED section of the Extensions menu in VS Code.

Signing in

Before you can execute SQL statements or use the Snowpark Python features, you must sign in to a Snowflake account.

You can sign into Snowflake using your Snowflake account identifier, username, and password, or using federated authentication to Snowflake using SAML SSO.

The first time you sign into Snowflake from the VS Code extension, you need to add your account by entering either the account identifier for your Snowflake account or the URL that you use to connect to Snowflake.

See Account identifiers for details on how to determine your account identifier.

To sign into Snowflake from the VS Code extension, do the following:

  1. In the Activity Bar, click the Snowflake icon.

    The side bar panel changes to Snowflake navigation, and displays the Add Account or Sign in dialogs.

  2. Under Add Account, enter either the account identifier, and select Continue.

    Add Account is only displayed if no account was previously specified.

  1. Enter a username and password for the selected account and select Sign in.

On successful sign in, the sidebar changes to display the session context (ACCOUNT), DATABASE EXPLORER for the user in their default role, and QUERY HISTORY.

Using Snowflake Extension for Visual Studio Code with SnowSQL configuration files

The Snowflake Extension for Visual Studio Code can use Snow SQL configuration files for loading connection configurations.

Note

Only connection configuration values are used. Other SnowSQL configuration values are ignored.

To configure Snowflake Extension for Visual Studio Code to use a Snow SQL configuration file, do the following:

  1. In the Activity Bar, select the Snowflake icon.

    The side bar panel changes to Snowflake navigation, and displays the Add Account or Sign in dialogs.

  2. Select the Username drop down, and then select Sign in to another account.

  3. Select Use SnowSQL Config. The Visual Studio code settings page for the Snowflake Extension for Visual Studio Code opens with SnowSQL Config Path selected.

  4. Enter a path to a valid SnowSQL configuration file.

The account drop down updates to include all connections defined in the specified configuration file.

Working with SQL files

You can use the Snowflake Extension for Visual Studio Code to create and load SQL files. SQL files are simple text files that contain one or more SQL statements.

Opening SQL files

To create or open Snowflake SQL files, do the following:

  1. Select File » Open, navigate to and open a text file containing SQL.

    If you don’t have an existing SQL file, you can create a new one. Select File » New File and create a file of type Snowflake SQL File. Alternatively, select (New SQL file button) in the Database explorer panel to create a new SQL file.

  2. Add one or more Snowflake SQL statements to the file.

  3. Select a line and press [Execute], above the line, to execute the command.

Executing commands or queries

To execute one or more commands or queries, do the following:

  1. Select the Execute all statements button for the selected SQL file to execute all statements in that file.

  2. Select a line to run by placing your cursor on the statement to be run.

    Select two or more commands - All selected commands will be executed.

  3. Press the [Execute] button above the first command selected.

If you select multiple commands, the commands execute in order from top to bottom.

You can also run statements using keyboard shortcuts. After selecting the SQL statements you want to run, press Apple OSX Command key. + [enter] on a Mac keyboard, or Generic control key. + [enter] on a Windows keyboard.

You can see the results of the SQL statement in the SNOWFLAKE:QUERY RESULTS table of the Output section.

Tip

In-progress queries can be cancelled. To cancel a query in process, find the query in QUERY HISTORY and select cancel query (Cancel query button).

Using Query History

Query results are tracked in QUERY HISTORY.

To examine previously executed query results, do the following:

  1. Expand Query History.

  2. Select a statement.

  3. Examine the result in the SNOWFLAKE:QUERY RESULTS tab of the Output pane.

Tip

You can use the Query History to rerun a query(Rerun query button), copy the query text to the clipboard(Copy query text to clipboard button), or delete a query (Delete query button).

Working with query results

You can sort, reorder, hide, freeze, or save query results to disk.

To modify the display of a given query, do the following:

  1. In QUERY HISTORY, select a query.

  2. In QUERY RESULTS, choose a column.

  3. Select the down arrow (↓) and then one of: SORT A-Z (descending), Sort Z-A (ascending), Hide column “column name”, or Freeze columns up to “column name”.

The content display will change appropriately.

Tip

If a column was previously hidden, choose any other column and select Unhide N columns.

To save the results of a query to disk, select either disk (Download results button) or download (Save results button) associated with the query. Contents will be saved in a file, either as a compressed gzip, or as a comma-separated file.

Working with Snowpark Python code

You can use the Snowflake Extension for Visual Studio Code to write and debug Snowflake SQL statements in Snowpark Python code.

Debugging Snowpark Python functions

To debug a Snowpark Python function:

  1. Write a Snowflake stored procedure in a Python function where the first parameter is a Snowpark Session object.

  2. You should see an inline Snowflake: Debug option appear above the function name. Choose this option to run the stored procedure in the function, using your current active session through the extension. You can also set debug breakpoints.

Syntax highlighting and autocomplete for SQL in Python

You can add syntax highlighting of SQL in Python code by enabling automatic detection, or by using comments to manually denote SQL strings.

Detect SQL statements automatically

To set up automatic SQL syntax highlighting, enable the extension setting Auto Detect Sql in Python. The extension automatically detects SQL statements by looking for a SQL keyword in all capital letters as the first word in a Python string, as shown in the following screenshot.

A code snippet of a Snowflake SQL statement in a Python string showing automatic SQL syntax highlighting.

Denote SQL statements manually

To manually denote a SQL statement in a Python string:

  1. (Optional) Disable the extension setting Auto Detect Sql in Python.

  2. Use comments to denote the start and end of a SQL statement. You can use any combination of the following markers:

    • Start markers: -–startsql, -–beginsql, -–start-sql, -–begin-sql

    • End markers: –-endsql, –-end-sql

For example, the following screenshot shows code that uses --begin-sql and --end-sql to manually denote a SQL statement.

A code snippet of a Snowflake SQL statement in a Python string using comments to manually enable SQL syntax highlighting.

Use SQL autocomplete in Python strings

To use autocomplete for SQL statements in Python strings:

  1. In a Python file, create a Python string while connected to an active Snowflake session through the extension.

  2. Start writing a SQL statement and see the autocomplete suggestions that appear.

For example, when you start writing a statement such as SELECT * FROM db1.public, the extension automatically suggests table names.

Similarly, when you start filling out columns inside a SELECT statement that references a table, the extension automatically suggests column names, as shown in the following screenshot.

A code snippet of a Snowflake SQL statement in a Python string showing autocomplete suggestions for column names.

Jinja template syntax highlighting

By default, the extension adds basic syntax highlighting and bracket autocomplete for writing Jinja templates in Snowflake SQL, as shown in the following screenshot.

A code snippet of a Snowflake SQL statement with a Jinja template showing syntax highlighting and bracket autocomplete.

Changing session context

You can use the Account section of the Side Bar panel to select roles, databases, schemas, and warehouses. Use the associated dropdown to select each as appropriate.

Tip

Use the account drop down to sign into, or switch between different accounts.

Sign in to, or switch between accounts.

View extension details

You can view the Snowflake SQL Visual Studio Code extension information at any time.

You can see the following details about the extension, including:

  • Version information: Which version of the extension is currently installed.

  • Changelog: Information by version about features added, changed, or updated.

  • Feature walkthroughs.

In addition, you can disable or enable the extension using the enabled/disable dropdown.

To view extension information, do the following:

  1. Select Code » Preferences » Extensions.

  2. Select the Snowflake VS Code SQL extension.

    You can also select View » Extensions or click the extensions button Extensions button in the Activities bar.

Show changelog

To view the changelog for the extension, you can also use the Show Change Log command:

  1. Open the Command Palette by pressing CMD+Shift+P on a Mac keyboard, or CTRL+Shift+P on a Windows keyboard.

  2. Enter the following command:

    Show Change Log
    
    Copy

Extension settings

The Snowflake Extension for Visual Studio Code supports the following settings:

Setting

Description

Default

Export CSV » Delimiter

Specifies delimiter for columns

Comma

Export CSV » Header

Enable inclusion of header row in exported CSV file

Enabled

Export CSV » Include Empty Rows

Enable inclusion of empty rows in exported CSV file

Exclude

Export CSV » Quotes

Enable double quotes around all values in exported CSV file

Enabled

Highlight Query

Enable background highlight on the current SQL statement

Enabled

Show Execute Above Statement

Enable a clickable execute action above each statement

Enabled

Snowsql Config Path

If set, connection configuration will be loaded from this file

Unset

Autocomplete Object Details

Show details of a Snowflake object after you select its autocomplete entry

Disabled

Set Client Session Keep Alive

Specifies whether to keep the session active indefinitely as long as the connection is active, regardless of activity. If not enabled, you must sign in again after four hours of inactivity.

Enabled

Autocomplete Variant Keys

Show OBJECT/VARIANT key autocomplete suggestions

Disabled

Object Explorer: Search

Enable search in object explorer

Enabled

Query History: Item Limit

Specifies the maximum number of queries shown in history. Showing more queries might affect performance.

1000

Extension settings in preview

The following extension settings are currently available for preview:

Setting

Description

Default

Syntax Highlighting: Auto Detect Sql in Python

Enable automatic syntax highlighting of SQL statements in Python strings

Enabled

Enable Public Preview Features

Enable public preview features for the extension

Disabled

Change extension settings

To change extension settings:

  1. On Windows/Linux select File » Preferences » Settings. . On macOS select Code » Preferences » Settings.

  2. In the Search settings text box enter Snowflake.

  3. Select the User or Workspace tabs to view or modify user specific or workspace specific settings.

  4. Close the Settings tab.

Uninstalling the extension

To disable or uninstall the extension, do the following:

  1. Select Code » Preferences » Extensions

  2. Select the extension.

  3. Right-click and choose Disable or Uninstall.