Snowflake Extension for Visual Studio Code¶
The Snowflake Visual Studio Code (VS Code) extension enables you 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.
You can install the VS Code extension from the Visual Studio marketplace, or you can download and install the .vsix
file.
Install the VS Code extension from Visual Studio Marketplace¶
Install the VS Code extension from a .vsix file¶
Download the extension:
Go to https://marketplace.visualstudio.com/items?itemName=snowflake.snowflake-vsc.
Click the Version History tab.
Click Download for the VS Code version you want to install. Note where the file is downloaded.
In VS Code, select Code » Settings » Extensions.
Click More (…) » Install from VSIX.
Browse to the location of 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.
Sign in to Snowflake with the VS Code extension¶
Before you can execute SQL statements or use Snowpark Python features, you must sign in to a Snowflake account.
To sign in to Snowflake with the VS Code extension you can:
Use your Snowflake account identifier, username, and password.
Use federated authentication such as Security Assertion Markup Language (SAML) or Single sign-on (SSO).
Use key-pair authentication.
The first time you use with the VS Code extension to sign in to Snowflake, you’ll need to enter the account identifier for your Snowflake account or the URL that you use to connect to Snowflake. To determine your account identifier, see Account identifiers.
Click the Snowflake icon in the VS Code Activity Bar.
In the Account Identifier/URL field, enter the account identifier for your Snowflake account or the URL that you use to connect to Snowflake, and then click Continue.
The Account Identifier/URL field isn’t available if you’ve previously provided your Snowflake account credentials.
Select one of the following options in the Auth Method list:
Select Single sign-on to use your SSO credentials to sign in to Snowflake.
Select Username/password to use your Snowflake username and password to sign in to Snowflake.
Select Key Pair to use your Snowflake username and password to sign in to Snowflake. To learn more about key-pair authentication, see Key-pair authentication and key-pair rotation.
Enter your credentials and then click Sign in.
When you select SSO, a separate authentication page opens after you enter your username and select Sign in with single sign-on. Enter your SSO credentials and then return to VS Code to complete the Snowflake sign in.
After you successfully sign in, the sidebar displays your account information, your default role, the OBJECT EXPLORER with a Databases list, and your QUERY HISTORY.
Edit the Snowflake connections.toml
file¶
You can add and modify connection definitions in the Snowflake connections.toml
configuration file. A connection definition is a collection of connection-related parameters. For more information about connecting to Snowflake with a TOML file, see Connecting using the connections.toml file.
The VS Code extension interface¶
The following table provides descriptions of the VS Code extension interface functional areas.
Item |
Description |
---|---|
1 |
Sidebar panel. Contains the Account, Object Explorer and Query History panes. Use this panel to specify account details, examine database objects, and examine query results. |
2 |
Snowflake SQL panel. Displays Snowflake SQL files. |
3 |
Query History panel. Shows recent queries. |
4 |
Query Results panel. Shows query results. Select a query to display its execution result. |
5 |
Current session. Shows current session information, including current role, database, schema, and active warehouse. |
Use the VS Code extension 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.
In the VS Code search field, enter
>user settings
and then select Preferences: Open User Settings.On the User tab, expand Extensions.
Scroll down and select Snowflake.
In the right pane, scroll down to Snowsql Config Path.
Enter a path to a valid SnowSQL configuration file.
All connections defined in the configuration display in the Account panel.
Work with SQL files¶
You can use the Snowflake Extension for Visual Studio Code to create and load SQL files. SQL files are text files that contain one or more SQL statements.
Open or create SQL files¶
In VS Code, select File » Open, browse to the location of a SQL file, and then open it.
To create a new SQL file, select File » New File and create a file of type Snowflake SQL File.
Add one or more Snowflake SQL statements to the file.
(Optional) Click Snowflake: Execute All Statements () to execute a command.
Execute commands or queries¶
Important
To display Snowflake query results, the VS Code extension automatically runs DESC RESULT '<query_id>'
in the background after every query. This process makes LAST_QUERY_ID()
inaccurate. For more information about the DESCRIBE RESULT command and its parameters, see DESCRIBE RESULT.
In VS Code, select one of the following options:
To execute all SQL statements in a file, click Snowflake: Execute All Statements ().
To execute a specific command, place your cursor on the statement you want to run and then click Execute.
To execute multiple commands, select the statements you want to run and then click Execute. The commands execute in order from top to bottom.
To use keyboard shortcuts to execute statements, select the SQL statements you want to run, press + [enter] on a Mac keyboard, or + [enter] on a Windows keyboard.
Executed SQL statement results display in the SNOWFLAKE panel.
To cancel in-progress queries, select a query in QUERY HISTORY list and click Cancel query ().
View query history¶
Work with query results¶
You can sort, reorder, hide, freeze, or save query results to disk.
In QUERY HISTORY, select a query.
In the SNOWFLAKE panel, choose a column.
Select the expander arrow (↓) and then one of: Sort Ascending, Sort Descending, Hide column “column name”, or Freeze columns up to “column name”.
If a column was previously hidden, choose any other column and select Unhide N columns.
(Optional) Select one of the following:
Work 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.
Debug Snowpark Python functions¶
Write a Snowflake stored procedure in a Python function where the first parameter is a Snowpark
Session
object.An inline Snowflake: Debug option appears 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.
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 image.
Denote SQL statements manually¶
(Optional) Disable the extension setting Auto Detect Sql in Python.
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
The following image shows how the
--begin-sql
and--end-sql
markers manually denote a SQL statement.
Use SQL autocomplete in Python strings¶
In a Python file, create a Python string while connected to an active Snowflake session with the VS Code extension.
Write a SQL statement. The autocomplete suggestions 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 image.
Jinja template syntax highlighting¶
By default, the VS Code extension adds basic syntax highlighting and bracket autocomplete for writing Jinja templates in Snowflake SQL, as shown in the following image.
Work with the Snowflake Native App Framework¶
You can use the VS Code extension to create and manage a Snowflake Native App. For more information about the Snowflake Native App Framework, see About the Snowflake Native App Framework.
Create a Snowflake Native App¶
In VS Code, open the Snowflake VS Code extension and sign in to Snowflake.
Expand the NATIVE APP pane and then click Create new from template.
Select one of the following:
Enter the folder name where you want to create the Snowflake Native App and then press Enter.
Press Enter to accept the default directory as the location for the Snowflake Native App.
Select one of the following:
Enter the URL for the GitHub repository where your Snowflake Native App templates are stored and then press Enter.
Press Enter to accept default GitHub Snowflake Native App template repository URL.
Select one of the following templates:
Select basic to create a Snowflake Native App with minimal code examples and guidance.
Select streamlit-python to create a Snowflake Native App with Python extension code and Streamlit code examples.
Select streamlit-java to create a Snowflake Native App with Java extension code and Streamlit code examples.
Select spcs-basic to create a Snowflake Native App with SPCS extension code and Streamlit code examples.
Deploy and open a Snowflake Native App¶
When using the Run (deploy and re-install) or Deploy options, the first snowflake.yml
file listed in the NATIVE APP pane is used. When multiple snowflake.yml
files are available, a prompt appears and you can select the snowflake.yml
file you want to use for the deployment.
After you deploy your Snowflake Native App, you can open it in Snowflake to manage access, view, add, and validate app packages, view logs and events, and modify privileges.
Select one of the following:
In the VS Code extension NATIVE APP pane, click Run (deploy and re-install). This is the recommended option when you have made significant changes and an application object is required.
In the VS Code extension NATIVE APP pane, click Deploy. This is the recommended option when you are deploying application packages and stage files and an application object is not required.
(Optional) Click the OUTPUT tab in the query results panel to view deployment progress.
In the NATIVE APP pane, click Open.
View Snowflake Native App application object status¶
In the VS Code extension NATIVE APP pane, expand your application.
Uninstalled application objects are blue.
Enable debug mode¶
Use debug mode to show application objects that are not visible to consumers. For example, shared content objects or objects not granted to a specific database role. For more information about debug mode and turning it on programmatically, see Enable debug mode.
In the VS Code extension NATIVE APP pane, click Debug Mode.
Click Enable Debug Mode.
Select Enable debug mode for all Native Apps operations.
Drop Snowflake Native App packages and application objects¶
Use the Teardown option to drop the application object and package defined in the resolved project definition.
In the VS Code extension NATIVE APP pane, click Teardown. A confirmation message appears when teardown is complete.
Change 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.
Use the account drop down to sign in to, or switch between different accounts.
Manage stage content¶
The Snowflake Extension for Visual Studio Code supports managing stage content directly in the Object Explorer.
List all the files in a stage¶
In the VS Code OBJECT EXPLORER, navigate to a stage.
Expand the stage to see all staged files.
Upload files from the local file system to a stage¶
The Snowflake Extension for Visual Studio Code only supports uploads for internal stages, all other operations work for both internal and external stages.
In the VS Code OBJECT EXPLORER, navigate to a stage and click Upload ().
Enter optional parameters for the upload operation. See PUT for a list of optional parameters.
Navigate to the folder containing upload files, and then select and upload one or more files.
Download files from a stage to a local file system¶
Remove files from a stage¶
See also REMOVE.
VS Code extension settings¶
The following table lists the Snowflake Extension for Visual Studio Code 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 |
VS Code extension preview settings¶
The following table lists the VS Code extension preview settings.
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 VS Code extension settings¶
Select one of the following:
On Windows/Linux select File » Preferences » Settings.
On macOS select Code » Settings » Settings.
In the Search settings field, enter Snowflake.
Select the User or Workspace tabs to view or modify user specific or workspace specific settings.
Close the Settings tab.
Show the VS Code extension changelog¶
Press CMD+Shift+P (Mac), or CTRL+Shift+P (Windows).
Enter the following command:
Show Change Log
Uninstall the VS Code extension¶
Select Code » Settings » Extensions
Select the extension.
Right-click and select Disable or Uninstall.