zihaozeng0021 opened a new issue, #2621:
URL: https://github.com/apache/age/issues/2621
# MERGE pattern with the same variable at both ends (self-loop) is rejected
with "multiple labels for variable ... are not supported"
### Configuration
Docker Image: `apache/age:release_PG18_1.8.0`
Image Digest:
`sha256:47a0b054c3663a3e64a25fc0c5a982f1b58348019274b326a691cdf77f78eb58`
PostgreSQL Version: `18.6`
Apache AGE Extension Version: `1.8.0`
Operating System: WSL2, Ubuntu 24.04.1 LTS
Installation Method: Docker
Query Interface: `psql` (`SELECT * FROM cypher('xgdb', $$ ... $$) AS (...)`)
---
### Description
A `MERGE` pattern that uses the same vertex variable at both ends of the edge
(a self-loop, e.g. `MERGE (src)-[rel:R2]->(src)`) is rejected with
`ERROR: multiple labels for variable 'src' are not supported`, even though
the pattern contains
no label syntax at all. The variable-reuse check appears to misinterpret the
repeated variable as
a multi-label specification.
---
### Steps to reproduce
1. Start the AGE container and connect with `psql`.
2. Create one vertex, then run the self-loop `MERGE`:
```sql
SELECT * FROM cypher('xgdb', $$ CREATE (a {k: 1}) $$) AS (r agtype);
SELECT * FROM cypher('xgdb', $$
UNWIND [{v: 1}] AS relData
MATCH (src {k: 1})
MERGE (src)-[rel:R2]->(src)
ON CREATE SET rel.v = -12
ON MATCH SET rel.v = 34
$$) AS (r agtype);
```
3. Controls:
```sql
SELECT * FROM cypher('xgdb', $$ MATCH (a)-[e:R]->(a) RETURN count(e) AS
self_edges $$) AS (c agtype);
SELECT * FROM cypher('xgdb', $$ MATCH (a {k: 1}) CREATE (a)-[:R7]->(a) $$)
AS (r agtype);
```
---
### Expected behaviour
openCypher allows the same variable at both ends of an edge pattern; a
self-loop `MERGE` is legal
(Neo4j accepts the identical shape) and should create one `R2` self-loop
edge.
---
### Actual behaviour
The statement is cleanly rejected on both fresh-container runs
(`rc=3` in both segments):
```text
ERROR: multiple labels for variable 'src' are not supported
LINE 4: MERGE (src)-[rel:R2]->(src)
^
```
The controls prove only the `MERGE` path is affected: `CREATE
(a)-[:R7]->(a)` with the same
variable at both ends succeeds (`r7_edges = 1`), and `MATCH (a)-[e:R]->(a)`
over an existing self-loop also works. This is a clean user-level rejection,
not an internal
error; no crash.
---
### Minimal reproduction
```sql
SELECT * FROM cypher('xgdb', $$ MERGE (src)-[rel:R2]->(src) $$) AS (r
agtype);
```
One existing vertex suffices; the rejection occurs during pattern analysis.
---
### Why this appears to be a bug
The error message names a constraint (multiple labels for a variable) that
the query does not
use; repeated use of one vertex variable in a `MERGE` pattern is legal
openCypher and is accepted
by AGE's own `CREATE` path. Upstream
[apache/age#979](https://github.com/apache/age/issues/979) reported the
identical error for
`MERGE (x:C)-[:A]->(x)` in 2021 and is still open, confirming this remains
unfixed on
`release_PG18_1.8.0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]