Snowsight Worksheet Shortcuts

When you thought your life using Snowflake couldn’t get easier

Why should you care?

  • You’re already using Snowsight everyday!
  • You’re still using Classic Console (oh no!)

Nearly all Snowflake customer accounts will be defaulted to Snowsight this year as part of our normal behavior change release process. While you can still navigate back to the Classic Console, that ability will be removed later in 2024. This means that Snowsight will soon be the only interface available. Check out the behavior change log for bundle information and timing.

Onto the good stuff!

Use the following shortcuts in your Snowsight worksheets. Both Mac and Windows options are provided below.

Add multiple cursors (2 options)

Do you need to edit multiple lines of code at the same time? Well, these shortcuts are for you! It certainly beats having to type the same code over and over again or copying and pasting many times.

Option 1

  • Mac: cmd + click
  • Windows: ctrl + click

Option 2

  • Mac: option + click + drag your cursor
  • Windows: alt + click + drag your cursor

Reorder lines of code

Forget highlighting with your cursor and then copying and pasting. Move entire lines up and down with ease.

  • Mac: option + up/down arrow
  • Windows: alt + up/down arrow

Add or remove a comment

This is particularly helpful for commenting multiple lines of code. If you’re just commenting one line of code, it’s the same number of key strokes (--) so choose what works best for you.

  • Mac: cmd + / (forward slash)
  • Windows: ctrl + / (forward slash)

Run your query

There’s nothing wrong with clicking on the Run button but I personally find that moving back and forth from keyboard to mouse can sometimes be disruptive to my flow.

  • Mac: cmd + return or ctrl + return
  • Windows: ctrl + enter

Find and replace

Perhaps the most self explanatory of them all.

  • Mac: cmd + shift + h
  • Windows: ctrl + shift + h

Focus on your results

If you need to analyze the results of your query in depth, it’s often helpful to hide the noise that is your query pane. Let your query results take up your whole screen so you can drill in where needed.

  • Mac: ctrl + option + up/down arrow
  • Windows: ctrl + alt + up/down arrow

Okay, the below are not keyboard shortcuts but Snowsight shortcuts nonetheless!

Enable highlighting

Highlighting in Snowsight is particularly great when you have multiple queries in a single worksheet. As long as you end each query with a ; semicolon, this will highlight the single query that your cursor is on and thus only execute that query when you’re ready to run it.

  • Click on Settings > Toggle Highlight Statements

Format your query

Who else is guilty of copying code into a fancy online editor or toggling between VSCode or another IDE just to copy back into a worksheet? Well, say no more! This shortcut has been around for a while and is valuable for rendering code more readable.

However, the styling is not customizable, so you will still likely format the code based upon your team’s standards.

  • Navigate to your Worksheet tab > click on the 3 dots > select Format Query

More shortcuts galore

Hover over the tab for the worksheet and select more actions for worksheet, then choose Show Shortcuts to view the shortcuts.

Below is the sample code I used. This code identifies long running and recurring queries in your Snowflake account, assuming you have access to the SNOWFLAKE.ACCOUNT_USAGE schema. It does not matter what code you are using as all of the shortcuts will apply. Consider this a bonus thank you for your attention and a quick reminder to make sure you don’t have any rogue queries ;)

-- Sample query: Identify long running and recurring queries
WITH query_history AS (
SELECT
user_name,
role_name,
execution_status,
query_id,
query_text,
query_tag,
query_parameterized_hash,
cluster_number AS wh_nbr,
CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', qh.start_time) AS start_ts,
CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', qh.end_time) AS end_ts,
ROUND((qh.queued_provisioning_time + qh.queued_repair_time + qh.queued_overload_time) / 60000, 3) AS queued_min,
ROUND(qh.compilation_time / 60000, 3) AS comp_min,
ROUND(qh.execution_time / 60000, 3) AS exec_min,
ROUND(qh.total_elapsed_time / 60000, 3) AS total_min,
ROUND((qh.bytes_written_to_result) / POW(1024, 2), 2) AS result_mb,
qh.rows_produced AS tot_row_cnt,
qh.partitions_scanned AS scanned_mp_cnt,
qh.partitions_total AS total_mp_cnt,
ROUND(qh.bytes_scanned / POW(1024, 2), 2) AS scanned_mb,
ROUND(qh.partitions_scanned / GREATEST(qh.partitions_total, 1), 3) AS scan_pct,
ROUND((qh.bytes_spilled_to_local_storage) / POW(1024, 2), 2) AS local_spill_mb,
ROUND((qh.bytes_spilled_to_remote_storage) / POW(1024, 2), 2) AS remote_spill_mb,
ROUND(qh.percentage_scanned_from_cache, 2)::NUMBER(3, 2) AS cache_pct
FROM
SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY qh
WHERE
start_time BETWEEN '2024-01-01' AND '2024-01-25'
--AND warehouse_name = 'your warehouse'
AND query_type = 'SELECT'
AND exec_min > 1
--ORDER BY total_min DESC, wh_nbr, start_ts
)
SELECT
query_parameterized_hash,
COUNT(query_id) AS run_count,
AVG(total_min) AS avg_total_min,
AVG(comp_min) AS avg_comp_min,
AVG(exec_min) AS avg_exec_min,
AVG(queued_min) AS avg_queued_min
FROM
query_history
GROUP BY
1
ORDER BY
run_count DESC, avg_exec_min DESC;

Additional information

--

--