> ## 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.

> 使用 TimeSeries 表中的数据，在一段评估时间范围内对 prometheus 查询求值。

# prometheusQueryRange

使用 TimeSeries 表中的数据，在一段评估时间范围内对 prometheus 查询求值。

<div id="syntax">
  ## 语法
</div>

```sql theme={null}
prometheusQueryRange('db_name', 'time_series_table', 'promql_query', start_time, end_time, step)
prometheusQueryRange(db_name.time_series_table, 'promql_query', start_time, end_time, step)
prometheusQueryRange('time_series_table', 'promql_query', start_time, end_time, step)
```

<div id="arguments">
  ## 参数
</div>

* `db_name` - TimeSeries 表所在的数据库名称。
* `time_series_table` - TimeSeries 表的名称。
* `promql_query` - 按 [PromQL 语法](https://prometheus.io/docs/prometheus/latest/querying/basics/) 编写的查询。
* `start_time` - 评估范围的起始时间。
* `end_time` - 评估范围的结束时间。
* `step` - 用于将评估时间从 `start_time` 逐步推进到 `end_time` (含两端) 的步长。

<div id="returned_value">
  ## 返回值
</div>

该函数会根据传递给参数 `promql_query` 的查询结果类型，返回不同的列：

| 结果类型   | 结果列                                                                                    | 示例                                  |
| ------ | -------------------------------------------------------------------------------------- | ----------------------------------- |
| 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"')   |

<div id="example">
  ## 示例
</div>

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