Stephaneke opened a new issue, #1954: URL: https://github.com/apache/age/issues/1954
I am working with Apache AGE and I am trying to create new nodes and relationships based on existing nodes and their relationships. Here is a simplified version of my schema and queries. These can be used to reproduce the problem. I wanted to look for existing relationships and create new nodes and relationships connected to the found nodes. However, it seems to be able to find the nodes, but when adding the WITH statement, it no longer creates nodes and is unable to find them. This works fine in a neo4j context, so i assume this is a bug with the WITH clause. ### Schema Setup preparation script (if age extension does not exist). ```sql CREATE EXTENSION age; SET search_path = ag_catalog; ``` pastable setup script: ```sql -- Create the graph SELECT create_graph('my_graph'); -- Add NodeType1 nodes SELECT * FROM cypher('my_graph', $$ CREATE (:NodeType1 {name: 'A', project: 'PROJECT_ID'}) CREATE (:NodeType1 {name: 'B', project: 'PROJECT_ID'}) CREATE (c:NodeType1 {name: 'C', project: 'PROJECT_ID'}) return c $$) AS (c agtype); -- Add NodeType2 nodes SELECT * FROM cypher('my_graph', $$ CREATE (:NodeType2 {name: '1', project: 'PROJECT_ID'}) CREATE (b:NodeType2 {name: '2', project: 'PROJECT_ID'}) return b $$) AS (b agtype); -- Add relationships between NodeType1 and NodeType2 SELECT * FROM cypher('my_graph', $$ MATCH (a:NodeType1 {name: 'A', project: 'PROJECT_ID'}), (b:NodeType2 {name: '1', project: 'PROJECT_ID'}) CREATE (a)-[:RelType]->(b) return a, b $$) AS (a agtype, b agtype); SELECT * FROM cypher('my_graph', $$ MATCH (a:NodeType1 {name: 'B', project: 'PROJECT_ID'}), (b:NodeType2 {name: '1', project: 'PROJECT_ID'}) CREATE (a)-[:RelType]->(b) return a, b $$) AS (a agtype, b agtype); SELECT * FROM cypher('my_graph', $$ MATCH (a:NodeType1 {name: 'B', project: 'PROJECT_ID'}), (b:NodeType2 {name: '2', project: 'PROJECT_ID'}) CREATE (a)-[:RelType]->(b) return a, b $$) AS (a agtype, b agtype); SELECT * FROM cypher('my_graph', $$ MATCH (a:NodeType1 {name: 'C', project: 'PROJECT_ID'}), (b:NodeType2 {name: '2', project: 'PROJECT_ID'}) CREATE (a)-[:RelType]->(b) return a, b $$) AS (a agtype, b agtype); ``` ### Working Query (creates nodes but not relationships) ```cypher SELECT * FROM cypher('my_graph', $$ MATCH (node1:NodeType1)-[rel:RelType]->(node2:NodeType2) WHERE NOT exists((node1)-[:RelType2]-(:NodeType3)-[:RelType2]-(node2)) AND node1.project = 'PROJECT_ID' AND node2.project = 'PROJECT_ID' CREATE (newNode:NodeType3 { name: node1.name + '|' + node2.name, uri: 'https://example.com/ns#NodeType3', project: 'PROJECT_ID', executionType: 'AUTO' }) RETURN newNode $$) AS (newNode agtype); ``` ### Failing Query (tries to create relationships, but fails) ```cypher SELECT * FROM cypher('my_graph', $$ MATCH (node1:NodeType1)-[rel:RelType]->(node2:NodeType2) WHERE NOT exists((node1)-[:RelType2]-(:NodeType3)-[:RelType2]-(node2)) AND node1.project = 'PROJECT_ID' AND node2.project = 'PROJECT_ID' CREATE (newNode:NodeType3 { name: node1.name + '|' + node2.name, uri: 'https://example.com/ns#NodeType3', project: 'PROJECT_ID', executionType: 'AUTO' }) WITH node1 AS n1, node2 AS n2, newNode AS n3 MERGE (n1)-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]->(n3) MERGE (n2)-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]->(n3) RETURN n1, n2, n3 $$) AS (n1 agtype, n2 agtype, n3 agtype); ``` This results in the error: ``` Vertex assigned to variable n3 was deleted ``` ### Alternative Query (without WITH clause, also fails) ```cypher SELECT * FROM cypher('my_graph', $$ MATCH (node1:NodeType1)-[rel:RelType]->(node2:NodeType2) WHERE NOT EXISTS((node1)-[:RelType2]-(:NodeType3)-[:RelType2]-(node2)) AND node1.project = 'PROJECT_ID' AND node2.project = 'PROJECT_ID' CREATE (newNode:NodeType3 { name: node1.name + '|' + node2.name, uri: 'https://example.com/ns#NodeType3', project: 'PROJECT_ID', executionType: 'AUTO' }) MERGE (node1)-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]->(newNode) MERGE (node2)-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]->(newNode) RETURN node1, node2, newNode $$) AS (node1 agtype, node2 agtype, newNode agtype); ``` This also results in the error: ``` Vertex assigned to variable newNode was deleted ``` ### What We Have Tried - Using `WITH` clauses to alias variables. - Creating relationships directly after node creation. - Separating creation and merging steps into different parts of the query. None of these approaches have resolved the issue, and we consistently encounter the vertex deletion error. -- 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: dev-unsubscr...@age.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org