---
title: Update metric SQL model
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Experiments
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

# Update metric SQL model{% #update-metric-sql-model %}

{% tab title="v2" %}

| Datadog site      | API endpoint                                                                                 |
| ----------------- | -------------------------------------------------------------------------------------------- |
| ap1.datadoghq.com | PUT https://api.ap1.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id} |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id} |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/experiments/metric-sql-models/{metric_sql_model_id}      |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id}      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id}  |
| uk1.datadoghq.com | PUT https://api.uk1.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id} |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id}     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id} |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id} |

### Overview

Replace a metric SQL model. This is a destructive full replace: subject types, customer-defined measures, and properties absent from the body are deleted, so send the complete set. Properties are matched by name; changing a property's column, type, or description preserves its ID. column_type is required for every measure and property. Removing a measure or property that an active metric references returns 409 Conflict. Server-generated IDs returned by GET are read-only and can be left in a replayed body. The response reports removals in meta.deleted_subject_types, meta.deleted_measures, and meta.deleted_properties. Certification is read-only. Certified models cannot be replaced through this endpoint. This endpoint requires the `product_analytics_warehouse_model_write` permission.

OAuth apps require the `product_analytics_warehouse_model_write` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#experiments) to access this endpoint.



### Arguments

#### Path Parameters

| Name                                  | Type   | Description                       |
| ------------------------------------- | ------ | --------------------------------- |
| metric_sql_model_id [*required*] | string | The UUID of the metric SQL model. |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field  | Field                              | Type     | Description                                                                                                |
| ------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
|               | data [*required*]             | object   | Metric SQL model resource to create.                                                                       |
| data          | attributes [*required*]       | object   | Complete column mappings and query used to replace the metric SQL model.                                   |
| attributes    | date_partition_column              | string   | SQL column used to partition the source data by date.                                                      |
| attributes    | description                        | string   | Text that explains the metric SQL model.                                                                   |
| attributes    | measures                           | [object] | Measures available from the SQL model's result columns.                                                    |
| measures      | column_name [*required*]      | string   | SQL result column that contains the measure values.                                                        |
| measures      | column_type [*required*]      | enum     | Data type of a column in the SQL model. Allowed enum values: `STRING,INTEGER,FLOAT,BOOLEAN,DATE,TIMESTAMP` |
| measures      | description                        | string   | Description of the measure.                                                                                |
| measures      | migration_metadata                 |          | Metadata associated with migration of this resource.                                                       |
| measures      | name                               | string   | Display name of the measure.                                                                               |
| attributes    | migration_metadata                 |          | Metadata retained for resources imported from another system.                                              |
| attributes    | name [*required*]             | string   | Display name of the metric SQL model.                                                                      |
| attributes    | properties                         | [object] | Property columns exposed by the SQL model.                                                                 |
| properties    | column_name [*required*]      | string   | Name of the SQL result column that supplies this property.                                                 |
| properties    | column_type [*required*]      | enum     | Data type of a column in the SQL model. Allowed enum values: `STRING,INTEGER,FLOAT,BOOLEAN,DATE,TIMESTAMP` |
| properties    | description                        | string   | Optional text that explains what this property represents.                                                 |
| properties    | migration_metadata                 |          | Opaque metadata preserved when this property is migrated.                                                  |
| properties    | name [*required*]             | string   | Name used to identify the property in the model.                                                           |
| attributes    | sql [*required*]              | string   | SQL query that produces the model's source data.                                                           |
| attributes    | subject_types [*required*]    | [object] | Subject types mapped to columns in the SQL model.                                                          |
| subject_types | column_name [*required*]      | string   | SQL result column that contains the subject identifier.                                                    |
| subject_types | subject_type_id [*required*]  | string   | Identifier of the subject type mapped to this column.                                                      |
| attributes    | timestamp_column [*required*] | string   | SQL column that supplies the event timestamp.                                                              |
| data          | id                                 | string   | Optional JSON:API resource identifier field.                                                               |
| data          | type [*required*]             | enum     | Metric SQL models resource type. Allowed enum values: `metric-sql-models`                                  |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "date_partition_column": null,
      "description": null,
      "measures": [
        {
          "column_name": "revenue",
          "column_type": "STRING",
          "description": null,
          "migration_metadata": "undefined",
          "name": null
        }
      ],
      "migration_metadata": "undefined",
      "name": "Order facts",
      "properties": [
        {
          "column_name": "item_type",
          "column_type": "STRING",
          "description": null,
          "migration_metadata": "undefined",
          "name": "item_type"
        }
      ],
      "sql": "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
      "subject_types": [
        {
          "column_name": "user_id",
          "subject_type_id": "550e8400-e29b-41d4-a716-446655440010"
        }
      ],
      "timestamp_column": "created_at"
    },
    "id": "string",
    "type": "metric-sql-models"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Updated metric SQL model and its removed entries.

| Parent field  | Field                           | Type      | Description                                                                                                 |
| ------------- | ------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
|               | data [*required*]          | object    | JSON:API resource containing the metric SQL model identity and fields.                                      |
| data          | attributes                      | object    | Details of the metric SQL model.                                                                            |
| attributes    | certified_at                    | date-time | Time when this resource was certified.                                                                      |
| attributes    | created_at                      | date-time | Time when this resource was created.                                                                        |
| attributes    | date_partition_column           | string    | SQL column used to partition the source data by date.                                                       |
| attributes    | description                     | string    | Text that explains the metric SQL model.                                                                    |
| attributes    | event_count_measure_id          | string    | Read-only measure ID. Pass it as warehouse_metric_measure.id when the metric operation is count.            |
| attributes    | experiment_count                | int64     | Number of experiments that reference this resource.                                                         |
| attributes    | is_certified                    | boolean   | Whether this resource has been certified.                                                                   |
| attributes    | measures                        | [object]  | Measures available from the SQL model's result columns.                                                     |
| measures      | column_name                     | string    | Name of the SQL result column that supplies this measure.                                                   |
| measures      | column_type                     | enum      | Data type of a column in the SQL model. Allowed enum values: `STRING,INTEGER,FLOAT,BOOLEAN,DATE,TIMESTAMP`  |
| measures      | description                     | string    | Text that explains the measure.                                                                             |
| measures      | id                              | string    | ID of the measure.                                                                                          |
| measures      | migration_metadata              |           | Metadata retained for resources imported from another system.                                               |
| measures      | name                            | string    | Display name of the measure.                                                                                |
| attributes    | metric_count                    | int64     | Number of metrics that use this SQL model.                                                                  |
| attributes    | migration_metadata              |           | Metadata retained for resources imported from another system.                                               |
| attributes    | name                            | string    | Display name of the metric SQL model.                                                                       |
| attributes    | properties                      | [object]  | Property columns exposed by the SQL model.                                                                  |
| properties    | column_name                     | string    | Name of the SQL result column that supplies this measure.                                                   |
| properties    | column_type                     | enum      | Data type of a column in the SQL model. Allowed enum values: `STRING,INTEGER,FLOAT,BOOLEAN,DATE,TIMESTAMP`  |
| properties    | description                     | string    | Text that explains the measure.                                                                             |
| properties    | id                              | string    | ID of the measure.                                                                                          |
| properties    | migration_metadata              |           | Metadata retained for resources imported from another system.                                               |
| properties    | name                            | string    | Display name of the measure.                                                                                |
| attributes    | sql                             | string    | SQL query that produces the model's source data.                                                            |
| attributes    | subject_types                   | [object]  | Subject types mapped to columns in the SQL model.                                                           |
| subject_types | column_name                     | string    | Name of the SQL result column that identifies subjects of this type.                                        |
| subject_types | subject_type_id                 | string    | ID of the subject type used by this configuration.                                                          |
| subject_types | unique_subject_count_measure_id | string    | Read-only measure ID. Pass it as warehouse_metric_measure.id when the metric operation is `uniqueSubjects`. |
| attributes    | timestamp_column                | string    | SQL column that supplies the event timestamp.                                                               |
| attributes    | updated_at                      | date-time | Time when this resource was last updated.                                                                   |
| data          | id [*required*]            | uuid      | ID of the metric SQL model.                                                                                 |
| data          | type [*required*]          | enum      | Metric SQL models resource type. Allowed enum values: `metric-sql-models`                                   |
|               | meta                            | object    | Model entries removed by the update. Empty arrays mean no entries were removed.                             |
| meta          | deleted_measures                | [string]  | Measure column names removed from the model.                                                                |
| meta          | deleted_properties              | [string]  | Property names removed from the model.                                                                      |
| meta          | deleted_subject_types           | [string]  | Subject type IDs removed from the model.                                                                    |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "created_at": "2024-01-01T12:00:00Z",
      "event_count_measure_id": "550e8400-e29b-41d4-a716-446655440024",
      "is_certified": false,
      "measures": [
        {
          "column_name": "revenue",
          "column_type": "FLOAT",
          "id": "550e8400-e29b-41d4-a716-446655440021",
          "name": "revenue"
        }
      ],
      "name": "Order facts",
      "properties": [
        {
          "column_name": "item_type",
          "column_type": "STRING",
          "id": "550e8400-e29b-41d4-a716-446655440023",
          "name": "item_type"
        }
      ],
      "sql": "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
      "subject_types": [
        {
          "column_name": "user_id",
          "subject_type_id": "550e8400-e29b-41d4-a716-446655440010",
          "unique_subject_count_measure_id": "550e8400-e29b-41d4-a716-446655440022"
        }
      ],
      "timestamp_column": "created_at",
      "updated_at": "2024-01-01T12:00:00Z"
    },
    "id": "550e8400-e29b-41d4-a716-446655440020",
    "type": "metric-sql-models"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Malformed ID or body, validation failure, or the SQL was rejected by the warehouse validator.
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="401" %}
Missing or invalid authentication.
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Authenticated caller lacks the product_analytics_warehouse_model_write permission.
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="404" %}
No metric SQL model with this ID exists for the organization.
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="409" %}
The model is certified or managed by metric sync, or the update would remove a measure or property still used by an active metric.
{% tab title="Model" %}
API error response.

| Parent field | Field                    | Type     | Description                                                                     |
| ------------ | ------------------------ | -------- | ------------------------------------------------------------------------------- |
|              | errors [*required*] | [object] | A list of errors.                                                               |
| errors       | detail                   | string   | A human-readable explanation specific to this occurrence of the error.          |
| errors       | meta                     | object   | Non-standard meta-information about the error                                   |
| errors       | source                   | object   | References to the source of the error.                                          |
| source       | header                   | string   | A string indicating the name of a single request header which caused the error. |
| source       | parameter                | string   | A string indicating which URI query parameter caused the error.                 |
| source       | pointer                  | string   | A JSON pointer to the value in the request document that caused the error.      |
| errors       | status                   | string   | Status code of the response.                                                    |
| errors       | title                    | string   | Short human-readable summary of the error.                                      |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    {
      "detail": "Missing required attribute in body",
      "meta": {},
      "source": {
        "header": "Authorization",
        "parameter": "limit",
        "pointer": "/data/attributes/title"
      },
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Path parameters export metric_sql_model_id="550e8400-e29b-41d4-a716-446655440000" \# Use a Personal Access Token or Service Access Token export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"  \# Curl command curl -X PUT "https://api.datadoghq.com/api/v2/experiments/metric-sql-models/${metric_sql_model_id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "date_partition_column": null,
      "description": null,
      "measures": [
        {
          "column_name": "revenue",
          "column_type": "FLOAT",
          "description": null,
          "name": null
        }
      ],
      "name": "Order facts",
      "sql": "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
      "subject_types": [
        {
          "column_name": "user_id",
          "subject_type_id": "550e8400-e29b-41d4-a716-446655440010"
        }
      ],
      "timestamp_column": "created_at"
    },
    "type": "metric-sql-models"
  }
}
EOF 
                
##### 

```python
"""
Update metric SQL model returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.experiments_api import ExperimentsApi
from datadog_api_client.v2.model.experiments_create_exposure_sql_model_v2_request_data_attributes_items_column_type import (
    ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType,
)
from datadog_api_client.v2.model.experiments_create_exposure_sql_model_v2_request_data_attributes_subject_types_items import (
    ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems,
)
from datadog_api_client.v2.model.experiments_create_metric_sql_model_v2_request import (
    ExperimentsCreateMetricSQLModelV2Request,
)
from datadog_api_client.v2.model.experiments_create_metric_sql_model_v2_request_data import (
    ExperimentsCreateMetricSQLModelV2RequestData,
)
from datadog_api_client.v2.model.experiments_create_metric_sql_model_v2_request_data_attributes_measures_items import (
    ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems,
)
from datadog_api_client.v2.model.experiments_metric_sql_model_property_input import (
    ExperimentsMetricSQLModelPropertyInput,
)
from datadog_api_client.v2.model.experiments_update_metric_sql_model_v2_request_data_attributes import (
    ExperimentsUpdateMetricSQLModelV2RequestDataAttributes,
)
from datadog_api_client.v2.model.experiments_update_metric_sql_model_v2_request_data_type import (
    ExperimentsUpdateMetricSQLModelV2RequestDataType,
)
from uuid import UUID

body = ExperimentsCreateMetricSQLModelV2Request(
    data=ExperimentsCreateMetricSQLModelV2RequestData(
        attributes=ExperimentsUpdateMetricSQLModelV2RequestDataAttributes(
            date_partition_column=None,
            description=None,
            measures=[
                ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems(
                    column_name="revenue",
                    column_type=ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType.FLOAT,
                    description=None,
                    name=None,
                ),
            ],
            name="Order facts",
            properties=[
                ExperimentsMetricSQLModelPropertyInput(
                    column_name="item_type",
                    column_type=ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType.STRING,
                    description=None,
                    name="item_type",
                ),
            ],
            sql="SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
            subject_types=[
                ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems(
                    column_name="user_id",
                    subject_type_id="550e8400-e29b-41d4-a716-446655440010",
                ),
            ],
            timestamp_column="created_at",
        ),
        type=ExperimentsUpdateMetricSQLModelV2RequestDataType.METRIC_SQL_MODELS,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
    api_instance = ExperimentsApi(api_client)
    response = api_instance.update_metric_sql_model(
        metric_sql_model_id=UUID("550e8400-e29b-41d4-a716-446655440000"), body=body
    )

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
##### 

```ruby
# Update metric SQL model returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::ExperimentsAPI.new

body = DatadogAPIClient::V2::ExperimentsCreateMetricSQLModelV2Request.new({
  data: DatadogAPIClient::V2::ExperimentsCreateMetricSQLModelV2RequestData.new({
    attributes: DatadogAPIClient::V2::ExperimentsUpdateMetricSQLModelV2RequestDataAttributes.new({
      date_partition_column: nil,
      description: nil,
      measures: [
        DatadogAPIClient::V2::ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems.new({
          column_name: "revenue",
          column_type: DatadogAPIClient::V2::ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType::FLOAT,
          description: nil,
          name: nil,
        }),
      ],
      name: "Order facts",
      properties: [
        DatadogAPIClient::V2::ExperimentsMetricSQLModelPropertyInput.new({
          column_name: "item_type",
          column_type: DatadogAPIClient::V2::ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType::STRING,
          description: nil,
          name: "item_type",
        }),
      ],
      sql: "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
      subject_types: [
        DatadogAPIClient::V2::ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems.new({
          column_name: "user_id",
          subject_type_id: "550e8400-e29b-41d4-a716-446655440010",
        }),
      ],
      timestamp_column: "created_at",
    }),
    type: DatadogAPIClient::V2::ExperimentsUpdateMetricSQLModelV2RequestDataType::METRIC_SQL_MODELS,
  }),
})
p api_instance.update_metric_sql_model("550e8400-e29b-41d4-a716-446655440000", body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
##### 

```go
// Update metric SQL model returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
	"github.com/google/uuid"
)

func main() {
	body := datadogV2.ExperimentsCreateMetricSQLModelV2Request{
		Data: datadogV2.ExperimentsCreateMetricSQLModelV2RequestData{
			Attributes: datadogV2.ExperimentsUpdateMetricSQLModelV2RequestDataAttributes{
				DatePartitionColumn: *datadog.NewNullableString(nil),
				Description:         *datadog.NewNullableString(nil),
				Measures: []datadogV2.ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems{
					{
						ColumnName:  "revenue",
						ColumnType:  datadogV2.EXPERIMENTSCREATEEXPOSURESQLMODELV2REQUESTDATAATTRIBUTESITEMSCOLUMNTYPE_FLOAT,
						Description: *datadog.NewNullableString(nil),
						Name:        *datadog.NewNullableString(nil),
					},
				},
				Name: "Order facts",
				Properties: []datadogV2.ExperimentsMetricSQLModelPropertyInput{
					{
						ColumnName:  "item_type",
						ColumnType:  datadogV2.EXPERIMENTSCREATEEXPOSURESQLMODELV2REQUESTDATAATTRIBUTESITEMSCOLUMNTYPE_STRING,
						Description: *datadog.NewNullableString(nil),
						Name:        "item_type",
					},
				},
				Sql: "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders",
				SubjectTypes: []datadogV2.ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems{
					{
						ColumnName:    "user_id",
						SubjectTypeId: "550e8400-e29b-41d4-a716-446655440010",
					},
				},
				TimestampColumn: "created_at",
			},
			Type: datadogV2.EXPERIMENTSUPDATEMETRICSQLMODELV2REQUESTDATATYPE_METRIC_SQL_MODELS,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewExperimentsApi(apiClient)
	resp, r, err := api.UpdateMetricSQLModel(ctx, uuid.MustParse("550e8400-e29b-41d4-a716-446655440000"), body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `ExperimentsApi.UpdateMetricSQLModel`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `ExperimentsApi.UpdateMetricSQLModel`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
##### 

```java
// Update metric SQL model returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.ExperimentsApi;
import com.datadog.api.client.v2.model.ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType;
import com.datadog.api.client.v2.model.ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems;
import com.datadog.api.client.v2.model.ExperimentsCreateMetricSQLModelV2Request;
import com.datadog.api.client.v2.model.ExperimentsCreateMetricSQLModelV2RequestData;
import com.datadog.api.client.v2.model.ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems;
import com.datadog.api.client.v2.model.ExperimentsMetricSQLModelPropertyInput;
import com.datadog.api.client.v2.model.ExperimentsUpdateMetricSQLModelV2RequestDataAttributes;
import com.datadog.api.client.v2.model.ExperimentsUpdateMetricSQLModelV2RequestDataType;
import com.datadog.api.client.v2.model.ExperimentsUpdateMetricSQLModelV2Response;
import java.util.Collections;
import java.util.UUID;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    ExperimentsApi apiInstance = new ExperimentsApi(defaultClient);

    ExperimentsCreateMetricSQLModelV2Request body =
        new ExperimentsCreateMetricSQLModelV2Request()
            .data(
                new ExperimentsCreateMetricSQLModelV2RequestData()
                    .attributes(
                        new ExperimentsUpdateMetricSQLModelV2RequestDataAttributes()
                            .datePartitionColumn(null)
                            .description(null)
                            .measures(
                                Collections.singletonList(
                                    new ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems()
                                        .columnName("revenue")
                                        .columnType(
                                            ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType
                                                .FLOAT)
                                        .description(null)
                                        .name(null)))
                            .name("Order facts")
                            .properties(
                                Collections.singletonList(
                                    new ExperimentsMetricSQLModelPropertyInput()
                                        .columnName("item_type")
                                        .columnType(
                                            ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType
                                                .STRING)
                                        .description(null)
                                        .name("item_type")))
                            .sql(
                                "SELECT user_id, order_id, item_type, revenue, created_at FROM"
                                    + " analytics.orders")
                            .subjectTypes(
                                Collections.singletonList(
                                    new ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems()
                                        .columnName("user_id")
                                        .subjectTypeId("550e8400-e29b-41d4-a716-446655440010")))
                            .timestampColumn("created_at"))
                    .type(ExperimentsUpdateMetricSQLModelV2RequestDataType.METRIC_SQL_MODELS));

    try {
      ExperimentsUpdateMetricSQLModelV2Response result =
          apiInstance.updateMetricSQLModel(
              UUID.fromString("550e8400-e29b-41d4-a716-446655440000"), body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ExperimentsApi#updateMetricSQLModel");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
##### 

```rust
// Update metric SQL model returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_experiments::ExperimentsAPI;
use datadog_api_client::datadogV2::model::ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType;
use datadog_api_client::datadogV2::model::ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems;
use datadog_api_client::datadogV2::model::ExperimentsCreateMetricSQLModelV2Request;
use datadog_api_client::datadogV2::model::ExperimentsCreateMetricSQLModelV2RequestData;
use datadog_api_client::datadogV2::model::ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems;
use datadog_api_client::datadogV2::model::ExperimentsMetricSQLModelPropertyInput;
use datadog_api_client::datadogV2::model::ExperimentsUpdateMetricSQLModelV2RequestDataAttributes;
use datadog_api_client::datadogV2::model::ExperimentsUpdateMetricSQLModelV2RequestDataType;
use uuid::Uuid;

#[tokio::main]
async fn main() {
    let body = ExperimentsCreateMetricSQLModelV2Request::new(
        ExperimentsCreateMetricSQLModelV2RequestData::new(
            ExperimentsUpdateMetricSQLModelV2RequestDataAttributes::new(
                "Order facts".to_string(),
                "SELECT user_id, order_id, item_type, revenue, created_at FROM analytics.orders"
                    .to_string(),
                vec![
                    ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems::new(
                        "user_id".to_string(),
                        "550e8400-e29b-41d4-a716-446655440010".to_string(),
                    ),
                ],
                "created_at".to_string(),
            )
            .date_partition_column(None)
            .description(None)
            .measures(vec![
                ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems::new(
                    "revenue".to_string(),
                    ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType::FLOAT,
                )
                .description(None)
                .name(None),
            ])
            .properties(vec![ExperimentsMetricSQLModelPropertyInput::new(
                "item_type".to_string(),
                ExperimentsCreateExposureSQLModelV2RequestDataAttributesItemsColumnType::STRING,
                "item_type".to_string(),
            )
            .description(None)]),
            ExperimentsUpdateMetricSQLModelV2RequestDataType::METRIC_SQL_MODELS,
        ),
    );
    let configuration = datadog::Configuration::new();
    let api = ExperimentsAPI::with_config(configuration);
    let resp = api
        .update_metric_sql_model(
            Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").expect("invalid UUID"),
            body,
        )
        .await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
{% /tab %}
