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

# Snowflake

> Connect Snowflake to ClarityQ

## Setup

### Step 1: Create a dedicated user for ClarityQ

Connect to Snowflake and create a service account:

```sql theme={null}
-- Create a user with the public key authentication
CREATE USER clarityq_user
  RSA_PUBLIC_KEY='<paste-public-key-here>'
  DEFAULT_ROLE = clarityq_role
  COMMENT = 'User for ClarityQ to access specific table';
```

### Step 2: Create and configure a role

Set up appropriate permissions through a dedicated role:

```sql theme={null}
-- Create a dedicated role with limited permissions
CREATE ROLE clarityq_role;

-- Grant SELECT permission on the specific table
GRANT USAGE ON DATABASE ALIEN_EVENTS TO ROLE clarityq_role;
GRANT USAGE ON SCHEMA ALIEN_EVENTS.PUBLIC TO ROLE clarityq_role;
GRANT SELECT ON TABLE ALIEN_EVENTS.PUBLIC.ALIEN_EVENTS TO ROLE clarityq_role;
-- Or grant access to all the tables in the schema
GRANT SELECT ON ALL TABLES IN SCHEMA ALIEN_EVENTS.PUBLIC TO ROLE clarityq_role;

-- Assign the role to the user
GRANT ROLE clarityq_role TO USER clarityq_user;
```

### Step 3: Create a ClarityQ warehouse (or use an existing one)

```sql theme={null}
-- Create or use existing warehouse
CREATE WAREHOUSE IF NOT EXISTS COMPUTE_WH
  WITH WAREHOUSE_SIZE = '{XSMALL | SMALL | MEDIUM | LARGE}'
  AUTO_SUSPEND = 300
  AUTO_RESUME = TRUE;

-- Grant usage permission
GRANT USAGE ON WAREHOUSE COMPUTE_WH TO ROLE CLARITYQ_ROLE;
```

### Step 4: Configure connection in ClarityQ

In the ClarityQ interface, fill out the connection form with the following fields:

#### Basic Fields (Required for all connections)

* **Connection Name**: Choose a name for this connection (e.g., "Production Snowflake")
* **Account**: Your Snowflake account identifier (e.g., `xy12345.us-east-1`)
* **User**: `clarityq_user` (the user you created in Step 1)
* **Warehouse**: Your warehouse name (e.g., `COMPUTE_WH`)
* **Database**: Your database name (e.g., `ANALYTICS_DB`)
* **DB Schema**: Schema name (e.g., `public`)
* **Role**: `clarityq_role` (the role you created in Step 2)

#### Authentication Type

Choose your authentication method using the toggle buttons:

**Password Authentication:**

* **Password**: Enter the password you set for `clarityq_user`

**Private Key Authentication:**

* **Private Key**: Paste your RSA private key (multi-line text field)

  **Key-pair authentication setup:**

  For enhanced security, configure RSA key-pair authentication:

  *Generate RSA key pair:*

  ```bash theme={null}
  # Generate private key
  openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt

  # Generate public key
  openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
  ```

  *Configure in Snowflake:*

  ```sql theme={null}
  -- Set public key for user
  ALTER USER clarityq_user SET RSA_PUBLIC_KEY='<contents_of_rsa_key.pub>';
  ```

## Connection parameters reference

### Required parameters

| Parameter   | Type   | Description                              | Example             |
| ----------- | ------ | ---------------------------------------- | ------------------- |
| `account`   | string | Snowflake account identifier with region | `xy12345.us-east-1` |
| `user`      | string | Snowflake username                       | `clarityq_user`     |
| `warehouse` | string | Compute warehouse name                   | `COMPUTE_WH`        |
| `database`  | string | Target database name                     | `ANALYTICS_DB`      |

### Optional parameters

| Parameter         | Type   | Default  | Description                     |
| ----------------- | ------ | -------- | ------------------------------- |
| `connection_name` | string | -        | Custom name for this connection |
| `db_schema`       | string | `public` | Default schema within database  |
| `role`            | string | -        | Snowflake role to use           |

### Authentication methods

Choose one of the following authentication methods:

#### Password authentication (default)

| Parameter  | Type   | Description   |
| ---------- | ------ | ------------- |
| `password` | string | User password |

#### Key-pair authentication

| Parameter     | Type   | Description               |
| ------------- | ------ | ------------------------- |
| `private_key` | string | Private key in PEM format |
