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

> ## Agent Instructions
> If you are an AI coding agent operating Cargo, install the agent skills first: paste `Install Cargo by following https://api.getcargo.io/INSTALL.md` into your session, or run `npx skills add getcargohq/cargo-skills`. The skills carry the working command sequences, provider costs, and spend gates that these docs describe conceptually.
> The skills index at https://raw.githubusercontent.com/getcargohq/cargo-skills/main/llms.txt lists every skill, recipe, and provider playbook individually. Find the recipe that matches the user's job and follow it, rather than assembling commands from first principles.
> Signing up is free: a new account starts with 100 free credits, valid for its first 30 days, and needs no card. `cargo-ai login --email you@company.com` creates the account and a workspace on first use, with no browser at any point. Tell the user this before asking them to sign up.
> Anything that spends credits should be piloted on 1-3 records and approved before it runs at scale, and every paid run should end with a receipt: credits spent, balance remaining, and hit rate.

# Querying Cargo data

> Access your Cargo data models directly via SQL

Every data model you create in Cargo — whether an [object model](https://docs.getcargo.ai/models/object-models.md), an integration model, or a unified model — is stored as a table in your connected data warehouse. You can query these tables directly using SQL, whether from your own BI tools, data pipelines, or within Cargo to create new SQL-based models.

## Query from the CLI

The fastest path is `cargo-ai storage query`. Reference each model **logically** as `<dataset-slug>.<model-slug>` — Cargo validates it against your models and rewrites it to the real warehouse table, so you never hand-build a physical table name:

```bash theme={null}
cargo-ai storage model list                    # → your models and their dataset/model slugs
cargo-ai storage model get-ddl <model-uuid>    # → exact column names + types

cargo-ai storage query execute \
  "SELECT COUNT(*) AS total FROM crm.companies WHERE employee_count > 500"
# → {"outcome":"queried","rows":[{"total":142}]}
```

> [!WARNING]
>
> In `storage query`, every table **must** be written as
> `<dataset-slug>.<model-slug>` (e.g. `crm.companies`) — a bare name or a physical
> warehouse name is rejected. Only `SELECT` statements are allowed. Run
> `model get-ddl` to confirm the exact column names and types before querying.

***

## Table naming conventions

How you name a table depends on **how** you query.

### In `cargo-ai storage query` (recommended)

Reference models logically as `<dataset-slug>.<model-slug>`:

```sql theme={null}
SELECT * FROM crm.companies      -- connector-backed model
SELECT * FROM object.accounts    -- object / unified model
```

Cargo rewrites the reference to the real warehouse table, so the same query works whether your system of record is BigQuery or Snowflake.

### Directly in your warehouse (BI tools, SQL console)

Querying the warehouse directly uses the **physical** table name, which depends on your warehouse and its configured scope. The building blocks are the schema `datasets_<connector-slug>` and the table `models_<model-slug>`:

**BigQuery**

| Scope | Physical table |
| - | - |
| Dataset | `` `<project>.<dataset>.datasets_<connector>__models_<model>` `` |
| Project | `` `<project>.<prefix>_datasets_<connector>.models_<model>` `` |

**Snowflake**

| Scope | Physical table |
| - | - |
| Database | `<DATABASE>.datasets_<connector>.models_<model>` |
| Schema | `<DATABASE>.<SCHEMA>.datasets_<connector>__models_<model>` |

> [!NOTE]
>
> In the single-container scopes (BigQuery **dataset**, Snowflake **schema**) the
> connector and model parts are joined with a double underscore (`__`). Always
> confirm the exact physical name with `cargo-ai storage model get-ddl <model-uuid>`.

***

## Query examples

These run through `cargo-ai storage query` using logical `<dataset>.<model>` references. To run them directly in your warehouse instead, substitute the physical table names from the conventions above.

### Basic query

```sql theme={null}
SELECT
  company,
  website,
  funding_amt,
  funding_type
FROM file.abm_raw
WHERE funding_amt > 1000000
```

### Joining multiple models

Combine data from different Cargo models:

```sql theme={null}
SELECT
  a.company,
  a.website,
  b.enrichment_data,
  c.activity_score
FROM crm.companies a
LEFT JOIN enrichment.company_data b
  ON a.domain = b.domain
LEFT JOIN analytics.scores c
  ON a.company_id = c.company_id
```

### Aggregations

```sql theme={null}
SELECT
  company,
  website,
  SUM(deal_value) as total_pipeline,
  COUNT(*) as deal_count
FROM crm.deals
WHERE stage != 'Closed Lost'
GROUP BY company, website
HAVING SUM(deal_value) > 10000
```

***

## Creating SQL models

You can create new Cargo data models by writing SQL queries against your existing tables. This is useful for combining data from multiple sources, applying transformations, or creating aggregated views.

![SQL model configuration](https://mintcdn.com/cargo/tpyAGzkZkjrztY7n/images/sql-models-2.png?fit=max\&auto=format\&n=tpyAGzkZkjrztY7n\&q=85\&s=228f289990a205ae9f2cdf22c17558e3)

**1. Add a new SQL model**

Navigate to your data models and create a new model. Select **SQL** as the object type.

**2. Write your SQL query**

Write a query that selects data from your existing Cargo tables using the naming conventions above.

```sql theme={null}
SELECT
  "company",
  "_emitted_at" AS emitted_at,
  "website",
  "hq",
  "funding_amt",
  "funding_type",
  "funding_date"
FROM CARGO_DB.datasets_file.models_abm_lk
```

> [!WARNING]
>
> Do not include `_id`, `_time`, `_title`, or `_segments` columns in your query—these are system columns that Cargo generates automatically. Column names also cannot start with `computed__`, `custom__`, or `metric__`, or contain `___` or `$`.

**3. Configure column mapping**

Map the required columns:

* **ID** — The unique identifier for each record
* **Title** — A human-readable label for records

**4. Preview and save**

Preview the query results to verify your data, then save the model.

***

## Next steps

> [card] [Workflows](https://docs.getcargo.ai/workflows/overview.md)
>
> Use model search, record, and custom column actions.

> [card] [BigQuery setup](https://docs.getcargo.ai/integration/big-query.md)
>
> Configure BigQuery as your data warehouse.

> [card] [Snowflake setup](https://docs.getcargo.ai/integration/snowflake.md)
>
> Configure Snowflake as your data warehouse.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.