> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Evaluates a prometheus query using data from a TimeSeries table.

# prometheusQuery

Evaluates a prometheus query using data from a TimeSeries table.

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
prometheusQuery('db_name', 'time_series_table', 'promql_query', evaluation_time)
prometheusQuery(db_name.time_series_table, 'promql_query', evaluation_time)
prometheusQuery('time_series_table', 'promql_query', evaluation_time)
```

<h2 id="arguments">
  Arguments
</h2>

* `db_name` - The name of the database where a TimeSeries table is located.
* `time_series_table` - The name of a TimeSeries table.
* `promql_query` - A query written in [PromQL syntax](https://prometheus.io/docs/prometheus/latest/querying/basics/).
* `evaluation_time - The evaluation timestamp. To evaluate a query at the current time, use `now()`as`evaluation\_time\`.

<h2 id="returned_value">
  Returned value
</h2>

The function can returns different columns depending on the result type of the query passed to parameter `promql_query`:

| Result Type | Result Columns                                                                         | Example                             |
| ----------- | -------------------------------------------------------------------------------------- | ----------------------------------- |
| vector      | tags Array(Tuple(String, String)), timestamp TimestampType, value ValueType            | prometheusQuery(mytable, 'up')      |
| matrix      | tags Array(Tuple(String, String)), time\_series Array(Tuple(TimestampType, ValueType)) | prometheusQuery(mytable, 'up\[1m]') |
| scalar      | scalar ValueType                                                                       | prometheusQuery(mytable, '1h30m')   |
| string      | string String                                                                          | prometheusQuery(mytable, '"abc"')   |

<h2 id="supported-promql-features">
  Supported PromQL Features
</h2>

<h3 id="selectors">
  Selectors
</h3>

Instant selectors, range selectors, label matchers (`=`, `!=`, `=~`, `!~`), offset modifiers, `@` timestamp modifiers, and subqueries.

<h3 id="functions">
  Functions
</h3>

| Category  | Functions                                                                                        |
| --------- | ------------------------------------------------------------------------------------------------ |
| Range     | `rate`, `irate`, `delta`, `idelta`, `last_over_time`                                             |
| Math      | `abs`, `sgn`, `floor`, `ceil`, `sqrt`, `exp`, `ln`, `log2`, `log10`, `rad`, `deg`                |
| Trig      | `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`   |
| DateTime  | `day_of_week`, `day_of_month`, `days_in_month`, `day_of_year`, `minute`, `hour`, `month`, `year` |
| Type      | `scalar`, `vector`                                                                               |
| Histogram | `histogram_quantile`                                                                             |
| Other     | `time`, `pi`                                                                                     |

**Note**: `histogram_quantile` uses linear interpolation on classic histogram buckets (identified by the `le` label). Native histograms are not yet supported, and the `phi` (quantile level) argument must currently be a constant scalar — expressions that vary per step such as `histogram_quantile(time() / 1000, ...)` are rejected with a `NOT_IMPLEMENTED` error.

<h3 id="operators">
  Operators
</h3>

All arithmetic (`+`, `-`, `*`, `/`, `%`, `^`), comparison (`==`, `!=`, `<`, `>`, `<=`, `>=` with optional `bool`), and logical (`and`, `or`, `unless`) binary operators, with `on()`/`ignoring()` and `group_left()`/`group_right()` modifiers.

Unary operators `+` and `-`.

<h3 id="aggregation-operators">
  Aggregation Operators
</h3>

`sum`, `avg`, `min`, `max`, `count`, `stddev`, `stdvar`, `group`, `quantile`, `topk`, `bottomk`, `limitk` — with optional `by()` or `without()` modifiers.

Not yet supported: `count_values`.

<h2 id="example">
  Example
</h2>

```sql theme={null}
SELECT * FROM prometheusQuery(mytable, 'rate(http_requests{job="prometheus"}[10m])[1h:10m]', now())
```
