apache / age

Graph database optimized for fast analysis and real-time data processing. It is provided as an extension to PostgreSQL.
https://age.apache.org
Apache License 2.0
2.84k stars 399 forks source link

SET on MERGE not storing edge properties inside the database on creation #1907

Open tvaeyens opened 1 month ago

tvaeyens commented 1 month ago

Describe the bug When using a MERGE for a relation between two nodes that is not present in the database, the properties are not stored inside the database.

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

What data setup do we need to do?

SELECT * FROM ag_catalog.create_graph('test_graph');

SELECT * from cypher('test_graph', $$
CREATE (n:Testnode {name: 'Test Node A'}) 
RETURN n
$$) as (n agtype);

SELECT * from cypher('test_graph', $$
CREATE (n:Testnode {name: 'Test Node B'}) 
RETURN n
$$) as (n agtype);

What is the necessary configuration info needed? N/A

What is the command that caused the error?

SELECT * FROM cypher('test_graph', $$
MATCH (a)
WHERE a.name= 'Test Node A'
MATCH (b)
WHERE b.name= 'Test Node B'
MERGE (a)-[r:RELATED_TO]->(b)
SET r = {property1: 'something', property2: 'else'}
RETURN r
$$) AS (r agtype);

This gives the following output which is correct:

{"id":1125899906842625,"label":"RELATED_TO","end_id":844424930131970,"start_id":844424930131969,"properties":{"property1":"something","property2":"else"}}

When executing the next query:

SELECT * FROM cypher('test_graph', $$
MATCH (a)-[r]->(b)
return a, r, b
$$) AS (a agtype, r agtype, b agtype);

This following output is received:

{"id":844424930131969,"label":"Testnode","properties":{"name":"Test Node A"}} ,{"id":1125899906842625,"label":"RELATED_TO","end_id":844424930131970,"start_id":844424930131969,"properties":{}} ,{"id":844424930131970,"label":"Testnode","properties":{"name":"Test Node B"}}

As you can see, the edge properties are not here anymore. Is this expected behavior? Or does this type of queries need to be formed in another way?

When looking inside the postgres database tables, the properties are also not there

Expected behavior I thought the edge properties would still be present when executing the last query.

Environment (please complete the following information):

Additional context N/A

jrgemignani commented 1 month ago

@tvaeyens I was able to reproduce your error -

psql-16.2-5432-pgsql=# SELECT * FROM cypher('test_graph', $$
psql-16.2-5432-pgsql$# MATCH (a)-[r]->(b)
psql-16.2-5432-pgsql$# return a, r, b
psql-16.2-5432-pgsql$# $$) AS (a agtype, r agtype, b agtype);
                                              a                                              |
                          r                                                                |
      b
---------------------------------------------------------------------------------------------+--------------------------------------
-------------------------------------------------------------------------------------------+----------------------------------------
-----------------------------------------------------
 {"id": 844424930131969, "label": "Testnode", "properties": {"name": "Test Node A"}}::vertex | {"id": 1125899906842625, "label": "RE
LATED_TO", "end_id": 844424930131970, "start_id": 844424930131969, "properties": {}}::edge | {"id": 844424930131970, "label": "Testn
ode", "properties": {"name": "Test Node B"}}::vertex
(1 row)

psql-16.2-5432-pgsql=#