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

# SQL Query

<Badge className="hny-badge-enterprise-addon" stroke>Ent+</Badge>

<Note>
  This feature is available as an add-on for the [Honeycomb Enterprise plan](https://www.honeycomb.io/pricing/).
  Please contact your Honeycomb account team for details.
</Note>

## Description

Write an SQL query to execute on a compatible database server and generate logs from the result.

## Supported Platforms

HTP Agent: `v1.40.0`+

| Platform | Metrics | Logs | Traces |
| :------- | :------ | :--- | :----- |
| Linux    |         | ✓    |        |
| Windows  |         | ✓    |        |
| macOS    |         | ✓    |        |

### Configuration

| Field                       | Description                                                                                                                                                                                                                                                                                                                                    |
| :-------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Driver                      | Which database driver should be used. Typically indicates which kind of database is being queried. Options include "postgres", "mysql", "snowflake", "sqlserver", "sap-hana", and "oracle".                                                                                                                                                    |
| Database Connection Options | A driver specific string specifying how to connect to the database. Usually contains information like host, port, authorization credentials, TLS configuration, and other connection options.                                                                                                                                                  |
| Query                       | The SQL query to run. The results of the query are used to generate the telemetry specified below.                                                                                                                                                                                                                                             |
| Log Body Column             | Defines the name of the column whose value will become the body for the generated log.                                                                                                                                                                                                                                                         |
| Tacking Column              | Used for parameterized queries. Defines the name of the column to retrieve for the parameter value on subsequent query runs. See this [OTel Documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlqueryreceiver#tracking-processed-results) for more information.                             |
| Tracking Start Value        | Used for parameterized queries. Defines the initial value of the tracking column to compare against on subsequent query runs. See this [OTel Documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlqueryreceiver#tracking-processed-results) for more information.                            |
| Collection Interval         | How frequently to execute queries to retrieve log data. Default is '10s'.                                                                                                                                                                                                                                                                      |
| Enable Tracking Storage     | If using tracking values, enable this to persist those values when the collector is restarted. Directory will be "\$OIQ\_OTEL\_COLLECTOR\_HOME/storage". See this [OTel Documentation](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/sqlqueryreceiver#tracking-processed-results) for more information. |
| Enable Query Logging        | Whether or not the collector should log the SQL query with associated parameters when the query is ran.                                                                                                                                                                                                                                        |

### Example Configuration

In this example, we are connecting to a postgres database using a postgres driver specific connection string. We are using a simple query which is retrieving rows of logs from a table. We are tracking the `id` column to avoid creating duplicate logs.

#### Web Interface

<img src="https://mintcdn.com/honeycomb/Rg0uasoUd2K6eCoq/_assets/images/htp/sql_query_source.png?fit=max&auto=format&n=Rg0uasoUd2K6eCoq&q=85&s=c240c08bf1b186e9fa797148e2e3bdb8" alt="Honeycomb Docs - SQL Query Source - image 1" width="2054" height="2246" data-path="_assets/images/htp/sql_query_source.png" />

#### Standalone Source

```yaml theme={}
apiVersion: bindplane.observiq.com/v1
kind: Source
metadata:
  id: sqlquery
  name: sqlquery
spec:
  type: sqlquery
  parameters:
    - name: driver
      value: 'postgres'
    - name: datasource
      value: 'postgresql://postgres:password@localhost:5432/production?sslmode=disable'
    - name: query
      value: 'select data, id from log_data where id > $1'
    - name: body_column
      value: 'data'
    - name: tracking_column
      value: 'id'
    - name: tracking_start_value
      value: '0'
    - name: interval
      value: '10s'
    - name: enable_storage
      value: true
    - name: enable_log_query_logging
      value: true
```
