---
title: "Update metric SQL model"
method: PUT
path: "/api/v2/experiments/metric-sql-models/{metric_sql_model_id}"
tags: ["Experiments"]
---

# Update metric SQL model

`PUT /api/v2/experiments/metric-sql-models/{metric_sql_model_id}`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/experiments/metric-sql-models/{metric_sql_model_id}`
- Auth: one of:
  - API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`
  - OAuth 2
    - Authorization code: `/oauth2/v1/authorize`
    - Token URL: `/oauth2/v1/token` scopes: `product_analytics_warehouse_model_write`
- TypeScript: <https://skmtc.dev/datadog/apis/datadog-api-v2-collection/docs/api/v2/experiments/metric-sql-models/:metric_sql_model_id/put.ts> (a function with typed inputs; its response is checked against the schema)

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.

## Path parameters

- `metric_sql_model_id` string, uuid, required: The UUID of the metric SQL model.

## Request body

- ExperimentsCreateMetricSQLModelV2Request: Request to create a SQL model that supplies metric data.
  - `data` ExperimentsCreateMetricSQLModelV2RequestData, required: Metric SQL model resource to create.
    - `attributes` ExperimentsUpdateMetricSQLModelV2RequestDataAttributes, required: Complete column mappings and query used to replace the metric SQL model.
      - `date_partition_column` string, nullable: SQL column used to partition the source data by date.
      - `description` string, nullable: Text that explains the metric SQL model.
      - `measures` ExperimentsCreateMetricSQLModelV2RequestDataAttributesMeasuresItems[]: Measures available from the SQL model's result columns.
        - `column_name` string, required: SQL result column that contains the measure values.
        - `column_type` 'STRING' | 'INTEGER' | 'FLOAT' | 'BOOLEAN' | 'DATE' | 'TIMESTAMP', required: Data type of a column in the SQL model.
        - `description` string, nullable: Description of the measure.
        - `migration_metadata` unknown
        - `name` string, nullable: Display name of the measure.
      - `migration_metadata` unknown
      - `name` string, required: Display name of the metric SQL model.
      - `properties` ExperimentsMetricSQLModelPropertyInput[]: Property columns exposed by the SQL model.
        - `column_name` string, required: Name of the SQL result column that supplies this property.
        - `column_type` 'STRING' | 'INTEGER' | 'FLOAT' | 'BOOLEAN' | 'DATE' | 'TIMESTAMP', required: Data type of a column in the SQL model.
        - `description` string, nullable: Optional text that explains what this property represents.
        - `migration_metadata` unknown
        - `name` string, required: Name used to identify the property in the model.
      - `sql` string, required: SQL query that produces the model's source data.
      - `subject_types` ExperimentsCreateExposureSQLModelV2RequestDataAttributesSubjectTypesItems[], required: Subject types mapped to columns in the SQL model.
        - `column_name` string, required: SQL result column that contains the subject identifier.
        - `subject_type_id` string, required: Identifier of the subject type mapped to this column.
      - `timestamp_column` string, required: SQL column that supplies the event timestamp.
    - `id` string: Optional JSON:API resource identifier field.
    - `type` 'metric-sql-models', required: Metric SQL models resource type.

## Response `200`

OK

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

## Other responses

- `400`: Malformed ID or body, validation failure, or the SQL was rejected by the warehouse validator.
- `401`: Missing or invalid authentication.
- `403`: Authenticated caller lacks the product_analytics_warehouse_model_write permission.
- `404`: No metric SQL model with this ID exists for the organization.
- `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.
- `429`: Too many requests

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/3f70db624329?raw)
