waleedahmed0001 commented on issue #988:
URL: https://github.com/apache/age/issues/988#issuecomment-1595844328
Yes, the behaviour of Cypher is expected, as it does not check for the
existence of a property on a node by default and instead returns null for
missing properties.
I am explaining it with another example.
Let's consider an example where we have a graph representing a social
network, with nodes representing users and edges representing relationships
between them. Each user node has different properties such as "name," "age,"
and "city."
Suppose we have the following nodes in our graph:
```
(:User {name: 'Alice', age: 25, city: 'New York'})
(:User {name: 'Bob', age: 30})
(:User {name: 'Charlie', city: 'London'}
```
If we execute a Cypher query to retrieve the "city" property of all users,
even though not all users have the "city" property, Cypher will handle it
gracefully.
```
MATCH (u:User)
RETURN u.city
```
The results of the above query will be:
```
│ u.city │
│ New York│
│ │
│ London │
```
As you can see, the query returns null for users who don't have the "city"
property. This behavior allows the query to proceed without throwing an error,
and you can still work with the returned data, handling null values
appropriately.
If you want to filter out nodes that don't have the "city" property, you can
use a WHERE clause to achieve that:
```
MATCH (u:User)
WHERE EXISTS(u.city)
RETURN u.city
```
This modified query will only return the "city" property for users who have
it defined:
```
│ u.city │
│ New York│
│ London │
```
By using the WHERE clause with EXISTS(u.city), we ensure that only nodes
with the "city" property are included in the result.
--
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]