apache / apache/age

Relationship created earlier in the same query is not matched after `WITH` and `UNWIND`

Open
#2,490 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

**Describe the bug**

A relationship created earlier in the same Cypher query is not matched as expected after a `WITH` and `UNWIND` pipeline.

The query creates one relationship, expands two identical lookup items with `UNWIND`, and attempts to match that relationship once for each input row. The resulting relationship count should be `2`, but the query evaluates the condition as false and returns `"FAIL"`.

**How are you accessing AGE (Command line, driver, etc.)?**

* Command line using interactive `psql`
* Executed through `docker exec`

```text
docker exec -it test psql -U postgres -d postgres
```

**What data setup do we need to do?**

Start Apache AGE:

```text
docker run --rm --name test -e POSTGRES_PASSWORD=agepass -p 5432:5432 apache/age:latest
```

Connect using interactive `psql`:

```text
docker exec -it test psql -U postgres -d postgres
```

Load AGE, configure the search path, and create the graph:

```pgsql
LOAD 'age';
SET search_path = ag_catalog, public;
SELECT create_graph('test');
```

No separate graph data setup is required because the affected query creates the nodes and relationship itself.

**What is the necessary configuration info needed?**

* Docker image: `apache/age:latest`
* PostgreSQL: `18.1`
* Apache AGE: `1.7.0`
* AGE extension installed by the Docker image
* `search_path` set to `ag_catalog, public`
* Operating system: WSL2, Ubuntu 24.04.1 LTS
* Installation method: Docker

**What is the command that caused the error?**

```pgsql
SELECT *
FROM cypher('test', $cypher$
CREATE (a:N)-[:R {id:1}]->(b:N)
WITH [{type:'R', id:1}, {type:'R', id:1}] AS items
UNWIND items AS item
MATCH ()-[r:R]->()
WHERE r.id = item.id
RETURN CASE
WHEN count(r) = 2 THEN 'PASS'
ELSE 'FAIL'
END AS value
$cypher$) AS (value agtype);
```

Actual result:

```text
value
--------
"FAIL"
(1 row)
```

**Expected behavior**

`UNWIND` should produce two input rows.

For each input row, the relationship created earlier in the same query should match `r.id = item.id`. The resulting `count(r)` should therefore be `2`, and the query should return:

```text
value
--------
"PASS"
(1 row)
```

**Environment (please complete the following information):**

* Apache AGE version: `1.7.0`
* PostgreSQL version: `18.1`
* Docker image: `apache/age:latest`
* Operating system: WSL2, Ubuntu 24.04.1 LTS
* Access method: interactive `psql` through `docker exec`

**Additional context**

The behavior was reproduced twice in clean Docker containers.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the query in interactive psql using the apache/age:latest Docker image, with AGE loaded and the test graph created. Trace how the Cypher CREATE, WITH, UNWIND, and MATCH stages handle the relationship, then verify the query returns "PASS" and count(r) is 2.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.