apache / apache/age

`UNION` of a boolean expression and a constant literal fails: `UNION types boolean and agtype cannot be matched`

Open
#2,512 1 comment 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

**Bug description**

Writing a Cypher query that unions a boolean expression with a constant literal — e.g. `RETURN true IS NOT NULL AS x UNION RETURN true AS x` — makes AGE generate a PostgreSQL UNION whose branch types do not match: the boolean expression is compiled to a native `boolean`, while the constant branch remains `agtype`. PostgreSQL rejects the whole query at parse time with error 42804 `UNION types boolean and agtype cannot be matched`. The statement is valid Cypher (it returns `true` in Neo4j) and is rejected before producing any result.

**Access method**

- Command line via `psql`, inside the official Docker container `apache/age:1.8.0`

**Data setup**

No data is required — the error reproduces on an empty graph. Only the graph itself must exist:

```pgsql
CREATE EXTENSION IF NOT EXISTS age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
SELECT create_graph('graph_test');
```

**Configuration**

- None beyond the stock AGE extension. No additional modules (no PostGIS, etc.), default `search_path` handling as shown above.

**Command that triggers the error**

```pgsql
SELECT * FROM cypher('graph_test', $$ RETURN true IS NOT NULL AS x UNION RETURN true AS x $$) AS (a agtype);
```

```
ERROR: UNION types boolean and agtype cannot be matched
LINE 1: ... true IS NOT NULL AS x UNION RETURN true AS x
^
```

The same error also occurs:

- with other boolean-only expressions in place of `true IS NOT NULL`, e.g. `RETURN NOT true AS x UNION RETURN true AS x`, `RETURN true IN [true] AS x UNION RETURN true AS x`, `RETURN true AND false AS x UNION RETURN true AS x`;
- with an unparenthesized comparison in one branch, e.g. `RETURN 1 = 1 AS x UNION RETURN true AS x`;
- regardless of which branch holds the boolean expression, e.g. `RETURN true AS x UNION RETURN true IS NOT NULL AS x` (message: `UNION types agtype and boolean cannot be matched`);
- without aliases, e.g. `RETURN true IS NOT NULL UNION RETURN true`.

Only unions whose branches are all `agtype` already work, e.g. `RETURN true AS x UNION RETURN true AS x`. The inferred branch type depends on expression shape rather than on the Cypher result type:
- `RETURN (1 = 1) AS x UNION RETURN true AS x` succeeds,
- while the same comparison without parentheses (`RETURN 1 = 1 AS x UNION RETURN true AS x`) fails.

**Environment**

- Version: 1.8.0 (official `apache/age:1.8.0` Docker image)
- PostgreSQL: 18.1 (Debian 18.1-1.pgdg13+2), x86_64

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the query through the cypher entry point using psql in the official apache/age:1.8.0 Docker container. Trace how UNION branches infer types, especially the differences between parenthesized and unparenthesized comparisons, and add regression coverage for the listed boolean-expression cases. Done means valid Cypher UNION queries no longer fail with boolean/agtype type-mismatch errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.