---
title: `covarsampmerge`
url: https://nexyron.tech/docs/cypher/functions/aggregation/covarsampmerge
description: covarsampmerge merges partial aggregate states for computes sample covariance for paired numeric values. It should receive state produced by the matching state function rather tha
---

# `covarsampmerge`

## Generic Description

`covarsampmerge` merges partial aggregate states for computes sample covariance for paired numeric values. It should receive state produced by the matching state function rather than ordinary business values.

Simple example:

```cypher
MATCH (d:Document)
WITH covarsampstate(properties(d).prize, size(d.title)) AS partial
RETURN covarsampmerge(partial) AS value
```

## Consumer-Level Explanation

Use `covarsampmerge` when the graph pattern has already selected the row grain and the next step is a trustworthy metric, not another traversal. Keep the aggregate in Cypher when planner visibility, grouped execution, materialized aggregate views, or assistant-authored query validation matter.

## More Detailed Explanation

`covarsampmerge` operates after `MATCH`, `WHERE`, `WITH`, procedure output, or document/map projection has shaped rows. For planner tooling the important distinction is whether this page documents a final aggregate, a state producer, or a state merger. Final aggregates return business-facing values; state functions return execution-facing summaries; merge functions combine those summaries and should not be treated as ordinary scalar math.

## Advanced Example

This example puts `covarsampmerge` after graph matching and time bucketing so the aggregate summarizes an explicit business grain rather than an accidental stream of rows.

```cypher
MATCH (u:User)-[e:VIEWED]->(d:Document)
TIME e.ts BETWEEN datetime('2025-01-01T00:00:00Z') AND datetime('2025-02-01T00:00:00Z')
WITH date_trunc('day', e.ts) AS day_bucket,
     covarsampstate(properties(d).prize, size(d.title)) AS partial_state
RETURN day_bucket,
       covarsampmerge(partial_state) AS merged_metric
ORDER BY day_bucket
```

## Real Use Cases

-   daily or cohort-level graph metrics built from matched relationships
-   document or payload profiling after extracting map/list fields into rows
-   feature and report queries that need the aggregate to remain visible to the planner

## Real Limitations And Tradeoffs

-   aggregate results only summarize rows that reached the aggregate; broad patterns can still create expensive or misleading groups
-   state and merge values are implementation-oriented summaries, not display-friendly business fields
-   statistical aggregates require meaningful numeric inputs and enough observations to support interpretation
