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

# Upsert Materialized View

> This upserts a materialized view from an existing query. If the materialized view with the given name

<Info>
  Minimum required API key scope: `Read/Write`
</Info>

<Note>
  * This endpoint will create a new matview if none exists for the given query ID, or update an existing one if the query ID matches.
  * It will fail to create a matview with the same name as an existing one, but for a different query ID
  * The name of the matview is just the last part of the matview, not including `dune.<your_team>.` and must be prefixed with `result_`
  * The `cron_expression` parameter must be passed in as a valid 5 section cron expression. [See here](https://crontab.guru/) for how to write them.
</Note>

<Tip>
  * The cron expression interval must be at least 15 minutes and at most weekly
</Tip>


## OpenAPI

````yaml POST /v1/materialized-views
openapi: 3.0.1
info:
  contact: {}
  description: Dune API
  title: DuneAPI
  version: '1.0'
servers:
  - url: https://api.dune.com/api
security: []
paths:
  /v1/materialized-views:
    post:
      summary: >-
        This upserts (create or replace) a materialized view from an existing
        query
      description: >-
        This upserts a materialized view from an existing query. If the
        materialized view with the given name
      parameters:
        - description: API Key for the service
          in: header
          name: X-Dune-Api-Key
          required: true
          schema:
            type: string
        - description: API Key, alternative to using the HTTP header X-Dune-Api-Key
          in: query
          name: api_key
          schema:
            type: string
      requestBody:
        content:
          '*/*':
            schema:
              $ref: '#/components/schemas/matviews.MatviewsUpsertRequest'
        description: MatviewsUpsertRequest
        x-originalParamName: body
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/matviews.MatviewsUpsertResponse'
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error400'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error401'
          description: Unauthorized
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error404'
          description: Not Found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error500'
          description: Internal Server Error
components:
  schemas:
    matviews.MatviewsUpsertRequest:
      properties:
        cron_expression:
          type: string
        expires_at:
          type: string
        is_private:
          type: boolean
        name:
          type: string
        performance:
          description: >-
            Performance tier for the refresh execution. Accepts `small`,
            `medium`, `large`.

            Omit to use the default tier for the source query's engine.
          type: string
        query_id:
          type: integer
      type: object
    matviews.MatviewsUpsertResponse:
      properties:
        execution_id:
          description: >-
            Unique identifier for the execution triggered to refresh the
            materialized view
          example: 01HZ065JVE23C23FM2HKWQP2RT
          type: string
        name:
          description: Unique identifier for the materialized view
          example: dune.dune.result_erc_20_token_summary
          type: string
      type: object
    models.Error400:
      properties:
        error:
          example: Bad Request
          type: string
      type: object
    models.Error401:
      properties:
        error:
          example: Invalid API Key
          type: string
      type: object
    models.Error404:
      properties:
        error:
          example: Object not found
          type: string
      type: object
    models.Error500:
      properties:
        error:
          example: Internal error
          type: string
      type: object

````