apache / apache/age-website

Update SET clause documentation

Open
#122 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
42
Forks
69
PR merge metrics
No merged PRs in 30d

Description

A SET clause syntax (`SET a = {..}`) is implemented and merged recently (https://github.com/apache/age/pull/468). It may be useful to add it in the documentation.

The following code from the test files shows how the syntax is used. It is similar to https://neo4j.com/docs/cypher-manual/current/clauses/set/#set-copying-properties-between-nodes-and-relationships.

```sql
...
SELECT * FROM cypher('cypher_set_1', $$ CREATE (a:Andy {name:'Andy', age:36, hungry:true}) $$) AS (a agtype);
SELECT * FROM cypher('cypher_set_1', $$ CREATE (a:Peter {name:'Peter', age:34}) $$) AS (a agtype);
SELECT * FROM cypher('cypher_set_1', $$ CREATE (a:Kevin {name:'Kevin', age:32, hungry:false}) $$) AS (a agtype);
SELECT * FROM cypher('cypher_set_1', $$ CREATE (a:Matt {name:'Matt', city:'Toronto'}) $$) AS (a agtype);
SELECT * FROM cypher('cypher_set_1', $$ CREATE (a:Juan {name:'Juan', role:'admin'}) $$) AS (a agtype);

-- test copying properties between entities
SELECT * FROM cypher('cypher_set_1', $$
MATCH (at {name: 'Andy'}), (pn {name: 'Peter'})
SET at = properties(pn)
RETURN at, pn
$$) AS (at agtype, pn agtype);

SELECT * FROM cypher('cypher_set_1', $$
MATCH (at {name: 'Kevin'}), (pn {name: 'Matt'})
SET at = pn
RETURN at, pn
$$) AS (at agtype, pn agtype);

-- test replacing all properties using a map and =
SELECT * FROM cypher('cypher_set_1', $$
MATCH (m {name: 'Matt'})
SET m = {name: 'Peter Smith', position: 'Entrepreneur', city:NULL}
RETURN m
$$) AS (m agtype);

-- test removing all properties using an empty map and =
SELECT * FROM cypher('cypher_set_1', $$
MATCH (p {name: 'Juan'})
SET p = {}
RETURN p
$$) AS (p agtype);

-- test assigning non-map to an enitity
SELECT * FROM cypher('cypher_set_1', $$
MATCH (p {name: 'Peter'})
SET p = "Peter"
RETURN p
$$) AS (p agtype);

SELECT * FROM cypher('cypher_set_1', $$
MATCH (p {name: 'Peter'})
SET p = sqrt(4)
RETURN p
$$) AS (p agtype);
...
```

Aside from that, two other SET syntaxes are being worked on. I will post update in this issue.
Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.