# Clickhouse

Marple integrates seamlessly with [Clickhouse](https://clickhouse.com/), a fast analytical database.&#x20;

### Required credentials

To connect, the following credentials are needed:

```json
// example
{
    "dbHost": "play.clickhouse.com",
    "dbPort": "443",
    "dbName": "play",
    "dbUser": "user",
    "dbPassword": "secret"
}
```

### Queries

Queries are executed using SQL. Marple offers predefined queries for fetching datasets, signals, and time-series data. Below are some example queries:

* To retrieve **datasets**:

```sql
select
    concat("carId", ' ', session) as display_name,
    "carId",
    event,
    session,
    min(time) as start,
    max(time) as stop,
    realtime
  from {{TABLE}}
  group by "carId", event, session, realtime
```

* To retrieve a **signal list:**

```sql
select 
  name,
  sum(count) as count,
  max(count):: double precision *(1e9) as frequency
  unit,
  description
from {{TABLE}}
where "carId" = '{{ dataset.carId }}'
group by name
```

* To retrieve the **time series data**

```sql
select time / 1e9 as "timestamp", value
from {{TABLE}}
where "carId" = '{{ dataset.carId }}'
{%- if timestamp_start %}
and ({{timestamp_start}} * 1e9)::bigint <= time
{%- endif %}
{%- if timestamp_stop %}
and ({{timestamp_stop}} * 1e9)::bigint >= time
{%- endif %}
and name = '{{ signal.name }}'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.marpledata.com/docs/marple-insight/setup-and-configuration/data-connection/supported-databases/clickhouse.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
