# Workspaces

Snowsight worksheets are the fastest way to run interactive SQL and Python against RWD. Open one, set your role and warehouse, and query. This page covers the two worksheet types, how to create and run them, and the warehouse/role context that decides whether your query runs at all.

## What worksheets are

A worksheet is a saved, runnable editor inside Snowsight (Snowflake’s web UI at `app.snowflake.com`), found under `Projects › Worksheets`. Each worksheet runs in its own session with a single role and warehouse — its *context*. There are two kinds:

| Type | What it runs | Use it for |
| --- | --- | --- |
| SQL worksheet | One or more SQL statements | Ad-hoc queries, cohort exploration, quick lookups — the default for most RWD work. |
| Python worksheet | A Snowpark `main(session)` handler | DataFrame-style transforms and light Python logic that stays inside Snowflake (no data egress). |

Reach for a SQL worksheet first. Use a Python worksheet when you want to chain Snowpark DataFrame operations or call Python libraries against the same data without pulling it out of the warehouse. For multi-cell, notebook-style work, use a Snowflake Notebook instead.

## Create and run a worksheet

Sign in to Snowsight at `app.snowflake.com` and go to `Projects › Worksheets`. Select `+` and choose **SQL Worksheet** or **Python Worksheet**. The new worksheet opens with a date/time title and defaults to your default role and warehouse.

- **SQL:** type your statements and run the current statement, or run all. Each statement executes on the worksheet’s warehouse.
- **Python:** Snowsight scaffolds a handler that receives a Snowpark `session`. Edit the body, set the handler and any packages in the settings panel, and run the whole worksheet.

```python
import snowflake.snowpark as snowpark
from snowflake.snowpark.functions import col

def main(session: snowpark.Session):
    df = session.table("LIMS_PUB.BASE_RENASIGHT")
    df = df.filter(col("casefile_id") == "CF-12345")
    df.show()
    return df  # returned DataFrame renders in Results
```

## Set your role and warehouse

At the start of a session, set the role you intend to use and a warehouse to run on. In a SQL worksheet the cleanest way is explicit `USE` statements at the top:

```sql
USE ROLE RWD_RESEARCHER_PHI_ROLE;
USE WAREHOUSE RWD_PRODUCTION_QUERY_INTERACTIVE_WH;
```

Pick the smallest warehouse that fits the workload. Replace `{ENV}` with `DEVELOPMENT`, `PREPRODUCTION`, or `PRODUCTION`.

| Use case | Warehouse | Who |
| --- | --- | --- |
| Ad-hoc queries, quick lookups | `RWD_{ENV}_QUERY_INTERACTIVE_WH` | Engineers, Researchers |
| Heavy analytics, large aggregations | `RWD_{ENV}_QUERY_ANALYTICS_WH` | Analysts |
| BI dashboards | `RWD_{ENV}_BI_WH` | Viewers |
| AI / Cortex / semantic views / Streamlit | `RWD_{ENV}_AI_WH` | Analysts, Streamlit devs |
| dbt / ETL transforms (admin only) | `RWD_{ENV}_ETL_TRANSFORM_WH` | Engineers |

> **No active warehouse selected**
>
> Without an active warehouse, SQL fails with `No active warehouse selected in the current session`. A worksheet only gets a default warehouse if your user has one set; otherwise the context warehouse is empty and you must pick one. Run `USE WAREHOUSE …` (or choose one in the context selector) before querying. Your role also needs `USAGE` on that warehouse — see the warehouse access matrix in the Role Reference.

## Switching role and warehouse mid-session

There are two ways to change the worksheet context. Either re-run `USE` statements:

```sql
USE ROLE RWD_ANALYST_PHI_ROLE;
USE WAREHOUSE RWD_PRODUCTION_QUERY_ANALYTICS_WH;
```

…or use the role and warehouse pickers in the worksheet’s context selector. The chosen context is preserved for future sessions and shared with everyone who opens the same worksheet. You can only select a role granted to you and a warehouse your role has `USAGE` on.

> **Python worksheets follow the context**
>
> A Python worksheet runs inside a Snowpark session whose role and warehouse come from the worksheet context — there is no `USE` statement to edit. Change the role/warehouse via the context selector before running.

## Persistence and sharing

Local edits autosave roughly every few seconds and are private to you until you run the worksheet; running publishes the latest version to anyone the worksheet is shared with. Snowsight keeps version history.

- **Share** a worksheet with other signed-in Snowsight users (or via link, if link sharing is enabled). Recipients can view, run, edit, and duplicate per the permission you grant.
- **Running** a shared worksheet requires the worksheet’s run-as role; recipients without it can still *duplicate* it and run the copy under their own role.
- **Viewing past results** requires the primary role that produced them.

> **Sharing crosses role boundaries — mind PHI**
>
> A shared worksheet carries its SQL and last results, and its run-as role may differ from the recipient’s. Do not share PHI worksheets or results with anyone whose role isn’t cleared for PHI. When in doubt, share the query text, not the results.

## Getting help

Stuck on a worksheet, role, or warehouse error? Ask in #rwd-snowflake-help.
