apache / apache/age

`avg(toFloat(...))` followed by `UNION` fails with `UNION types double precision and agtype cannot be matched`

Open
#2,553 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
4.8k
Forks
523
Avg merge
1d 2h
Merged PRs (30d)
9

Description

**Reproduction**

```sql
LOAD 'age';
SET search_path = ag_catalog, public;
SELECT ag_catalog.create_graph('age_issue_case19');

SELECT *
FROM ag_catalog.cypher('age_issue_case19', $$
RETURN avg(toFloat(1)) AS value
UNION ALL
RETURN null AS value
$$) AS (value agtype);
```

**Expected**

The query returns two rows: `1.0` and `null`. The equivalent query is
accepted by Neo4j, and AGE can return the aggregate by itself.

**Actual**

```text
ERROR: UNION types double precision and agtype cannot be matched
```

**Controls**

These queries succeed on the same fresh graph:

```cypher
RETURN avg(toFloat(1)) AS value
```

```cypher
RETURN toFloat(1) AS value
UNION ALL
RETURN null AS value
```

The failure is specific to combining the numeric aggregate result with a
`UNION` branch. It does not require a graph pattern, writes, an entity, or a
probe projection. Current-log Case 3197 and its full fixture reproduce this
error on AGE 1.8.0.

This is separate from #2525: #2525 requires a numeric aggregate to be used in
a `CASE WHEN ... IS NULL THEN ... ELSE ... END` expression and reports a
boolean conversion error. This reduction contains no `CASE` and fails during
`UNION` type resolution.

**Environment**

Apache AGE `1.8.0` on PostgreSQL `18.6`, Docker image
`apache/age:release_PG18_1.8.0`.

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied SQL reproduction on Apache AGE 1.8.0 and confirm the aggregate-plus-UNION type-resolution error. Trace the AGE/PostgreSQL UNION handling for the aggregate result, then verify that the query returns 1.0 and null while the standalone controls remain successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.