How to create an Auto Incremented (Serial) attribute in Apache AGE ?
For example in the following query I want to add a new attribute order_id
that is unique and auto incremented every time I add a new order.
SELECT *
FROM cypher('online_orders', $$
CREATE(:User{name:"user1" ,email : "[email protected]" , phone:"123456" });
$$) AS (result agtype)
3
Answers
Since the attributes of nodes and edges are stored as a JSON object in the
properties
column, I believe this cannot be achieved only with the openCypher syntax. Also, AGE stores the ID of every node and edge, so creating anorder_id
property might be redundant. But you could do something like: create the user and set theorder_id
property to be the same as the nodeid
.Apache AGE
does not provide built-in support for auto-incremented or serial properties. we can define properties for nodes and edges as needed, but for auto-increment there may be a custom logic, one can define.There is no support for AUTOINCREMENT in AGE. What you can do is define a custom function for this.
You can get the largest order_id before inserting the new record and then increment it with 1 and then insert the record.
Something like this might help(not tested):