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

# How to connect

> How to connect the Snowflake data source to Adriel: register a key pair, authenticate with a private key, and bind a table or view.

Snowflake is a cloud SQL data warehouse. Connecting it binds a single Snowflake table or view to an Adriel data source, and each widget compiles into one SQL query run live against the warehouse.

## Before you connect

The following are required:

* A Snowflake account and its account identifier (for example, `xy12345.us-east-1`).
* A Snowflake user with read access to the target tables: `USAGE` on the warehouse, database, and schema, plus `SELECT` on the tables or views to be connected.
* An RSA key pair, with the public key assigned to the Snowflake user. Authentication is key-pair (JWT) only — password, OAuth, MFA, and federated SSO are not supported.
* A warehouse to run queries, or a default warehouse set on the user.

To generate a key pair, run the following in a local terminal:

```bash theme={null}
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out reporting_rsa_key.p8 -nocrypt
openssl rsa -in reporting_rsa_key.p8 -pubout -out reporting_rsa_key.pub
```

The `.p8` file is the private key for the connection form; the `.pub` file is the public key registered on Snowflake. Assign the public key to the Snowflake user in a worksheet, then confirm it with `DESC USER reporting_user;`:

```sql theme={null}
ALTER USER reporting_user SET RSA_PUBLIC_KEY = '<contents of reporting_rsa_key.pub without the header and footer lines>';
```

Grant the minimum privileges the user needs, and optionally set a default warehouse so one need not be supplied on the connection form:

```sql theme={null}
GRANT USAGE ON WAREHOUSE reporting_wh TO USER reporting_user;
GRANT USAGE ON DATABASE analytics TO USER reporting_user;
GRANT USAGE ON SCHEMA analytics.public TO USER reporting_user;
GRANT SELECT ON ALL TABLES IN SCHEMA analytics.public TO USER reporting_user;
GRANT SELECT ON FUTURE TABLES IN SCHEMA analytics.public TO USER reporting_user;
ALTER USER reporting_user SET DEFAULT_WAREHOUSE = 'reporting_wh';
```

## Connect Snowflake

<Steps>
  <Step title="Select the Snowflake data source">
    On the **Data Sources** page, search for **Snowflake** and select it.
  </Step>

  <Step title="Enter the account and username">
    Enter the Snowflake **account identifier** (for example, `xy12345.us-east-1`) and the **username** of the Snowflake user that holds read access.
  </Step>

  <Step title="Paste the private key">
    Paste the full contents of the `.p8` **private key**, including the `BEGIN` and `END` lines. The key can be pasted as a single line or across multiple lines — it is normalized to valid PEM format before use.
  </Step>

  <Step title="Set the warehouse and role">
    Enter the **warehouse** used to run queries. Leave it blank only if the user has a default warehouse. The **role** field is optional; queries run under the user's default Snowflake role.
  </Step>

  <Step title="Optionally save the setup for reuse">
    Enable **Save setup for reuse?** to store a subset of the setup on the connection so it is pre-filled the next time a Snowflake data source is created from it — the **warehouse**, **database**, **schema**, **table or view**, and **filter key** selections. These fields are optional, are discovered live from the account when saved, and have no effect on the connection itself.
  </Step>

  <Step title="Submit to validate the connection">
    Click **Submit**. Saving the credentials triggers a JWT-authenticated connection test against Snowflake.
  </Step>

  <Step title="Select the database, schema, and table">
    Choose one **database**, **schema**, and **table** (or view) from the lists the connector discovers. Each data source binds to a single table or view.
  </Step>

  <Step title="Set the date column and save">
    Choose the **date column** used by the dashboard date-range control, set per-column aggregations, and optionally override the warehouse for this data source. Save the data source to make it queryable from widgets.
  </Step>
</Steps>

## What gets imported

Each widget load compiles into a single `SELECT` statement against the bound table or view, with `WHERE`, `GROUP BY`, `ORDER BY`, and `LIMIT` clauses derived from the widget configuration. Numeric columns aggregate into metrics; text, boolean, date, and semi-structured columns surface as breakdowns. Semi-structured types (`VARIANT`, `OBJECT`, `ARRAY`) are serialized to JSON strings, and timestamp-with-timezone types are converted to UTC.

For the complete type mapping, aggregation rules, caching, and limits, see the [Snowflake data reference](/data-sources/o-z/snowflake/data-reference).

## Troubleshooting

<AccordionGroup>
  <Accordion title="JWT token is invalid">
    The public key registered on the Snowflake user does not match the private key supplied to the connection. Run `DESC USER reporting_user;` to confirm the registered public key, regenerate the pair if needed, and re-register it with `ALTER USER ... SET RSA_PUBLIC_KEY`.
  </Accordion>

  <Accordion title="Default warehouse is not set">
    The data source has no warehouse configured and the user has no default warehouse. Supply a warehouse on the connection form, or run `ALTER USER reporting_user SET DEFAULT_WAREHOUSE = 'reporting_wh';`.
  </Accordion>

  <Accordion title="The private key is rejected on save">
    The connection accepts any reasonably formatted PEM key: escaped newlines are converted to real newlines, headers and footers are stripped and re-added, and the body is re-wrapped at 64 characters. If the key is still rejected, confirm the full `.p8` contents were pasted and that the matching public key is registered on the user.
  </Accordion>

  <Accordion title="Insufficient privileges on the table or warehouse">
    The user must hold `USAGE` on the warehouse, database, and schema, plus `SELECT` on the target table. Re-grant any missing privileges and retry the connection.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Snowflake data reference" href="/data-sources/o-z/snowflake/data-reference">
    Query model, field type mapping, caching, and limits for the Snowflake data source.
  </Card>

  <Card title="Snowflake FAQs" href="/data-sources/o-z/snowflake/faqs">
    Common questions and expected behaviors for the Snowflake data source.
  </Card>

  <Card title="How to connect PostgreSQL" href="/data-sources/o-z/postgres/how-to-connect">
    Connect the Postgres-family SQL data source Snowflake most closely mirrors.
  </Card>

  <Card title="How to connect Redshift" href="/data-sources/o-z/redshift/how-to-connect">
    Connect the other cloud data warehouse, with the same view-based patterns.
  </Card>

  <Card title="How to connect MySQL" href="/data-sources/g-n/mysql/how-to-connect">
    Connect the MySQL SQL data source.
  </Card>
</CardGroup>
