> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cometly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up a Snowflake destination

> Create a Snowflake role, service user, and access token so Cometly can load export data directly into your warehouse.

## Overview

A **Snowflake destination** is a reusable connection to a database and schema you own. Unlike an S3 or GCS destination — where Cometly writes Parquet files and you load them yourself — a Snowflake destination has Cometly **load the data directly into a table in your warehouse** on each run. Your warehouse's own compute does the load.

You give Cometly a role that can create and append to a table in one schema, and a token to authenticate with. Cometly handles the rest.

## Prerequisites

* A Snowflake account, and a role that can create warehouses, databases, roles, users, and network policies (typically `ACCOUNTADMIN`).
* A space administrator role in Cometly.

## Connect Cometly to Snowflake

<Steps>
  <Step title="Create the Snowflake objects">
    In Snowflake (as a role such as `ACCOUNTADMIN`), set up:

    * A **warehouse** for Cometly to run the load on.
    * A **database and schema** to hold the exported tables.
    * A **role** that can `CREATE TABLE` in that schema (grant it `USAGE` on the warehouse, database, and schema, plus `CREATE TABLE` on the schema).
    * A **network policy** — required for a service user's token to work. Restrict its allowed IPs for production use.
    * A **service user** (type `SERVICE`), granted the role above and governed by that network policy.
    * A **programmatic access token** on that service user, restricted to the role. Copy the token secret — it is shown only once.
  </Step>

  <Step title="Find your account identifier">
    ```sql theme={null}
    SELECT CURRENT_ORGANIZATION_NAME() AS org, CURRENT_ACCOUNT_NAME() AS account;
    ```

    Your account identifier is `org-account` (with a hyphen) — for example, `myorg-ab12345`. Use that,
    **not** the full `https://…snowflakecomputing.com` URL.
  </Step>

  <Step title="Add the destination in Cometly">
    In the dashboard, go to **Integrations → Snowflake → Add destination** and enter:

    <ParamField path="Name" type="string" required>
      A label for this destination, for example "Production warehouse".
    </ParamField>

    <ParamField path="Account identifier" type="string" required>
      Your `org-account` identifier from the query above.
    </ParamField>

    <ParamField path="Warehouse" type="string" required>
      The warehouse Cometly runs the load on, for example `cometly_wh`.
    </ParamField>

    <ParamField path="Database" type="string" required>
      The database that holds the target schema, for example `cometly_db`.
    </ParamField>

    <ParamField path="Schema" type="string" required>
      The schema Cometly creates the table in, for example `exports`.
    </ParamField>

    <ParamField path="Role" type="string" required>
      The role Cometly uses — it must be able to `CREATE TABLE` in the schema, for example `cometly_role`.
    </ParamField>

    <ParamField path="Access token" type="string" required>
      The programmatic access token secret from the setup script.
    </ParamField>

    Cometly runs a quick connection check on save. If it succeeds, the destination is connected.
  </Step>
</Steps>

<Note>
  The access token is encrypted at rest and never shown again. Programmatic access tokens **expire**
  (`DAYS_TO_EXPIRY`) — rotate the token in Snowflake and update the destination before then, or the
  export will start failing.
</Note>

<Warning>
  A service user's token only works when the user is governed by a **network policy** (created in the
  setup script above). Without one, Snowflake rejects the token. Restrict the policy's `ALLOWED_IP_LIST`
  for production use.
</Warning>

<Note>
  Cometly creates each export's table **as the role above**, so that role owns it. To let your own
  reporting roles read the exported tables, grant them access — a one-time **future grant** covers
  every table Cometly creates:

  ```sql theme={null}
  GRANT SELECT ON FUTURE TABLES IN SCHEMA cometly_db.exports TO ROLE <your_reporting_role>;
  ```
</Note>

## Next step

<Card title="Create an export" icon="cloud-arrow-up" href="/data-warehouse/create-export">
  Choose this destination, a dataset, a target table name, and a date range.
</Card>
