skip to Main Content

I am trying to match nodes a where the sizes for a.category are less than or equal to 9. I would like to place a condition for a.category sizes that are exactly the size of 9, that only the nodes with their first character being ‘c’ will be matched. Here is an example of what I want to achieve:

SELECT * FROM cypher('Graph', $$
    MATCH (a)
    WHERE size(a.category <= 9) AND
        substring(a.category, 0, 1)) = 'c' ONLY IF (size(a.category) = 9)
    RETURN a.name
$$) AS (name agtype);

If the IF statement does not exist or will not work in this circumstance, are there any ways to achieve the same result with a different method?

2

Answers


  1. use AND instead of IF

    like this

    SELECT * FROM cypher('Graph', $$
        MATCH (a)
        WHERE size(a.category <= 9) AND (size(a.category) = 9) AND substring(a.category, 0, 1)) = 'c'
        RETURN a.name
    $$) AS (name agtype);
    
    Login or Signup to reply.
  2. The situation you described can be achieved by the following query

    SELECT * FROM cypher('Graph', $$
    MATCH(a)
    WHERE (size(a.category) < 9) OR (size(a.category) = 9 AND 
    substring(a.category, 0,1) = 'c') 
    RETURN a.name $$) AS (name agtype); 
    

    You can split the logic as first matching if the size of category is 9 OR (size is 9 AND category starts with letter c).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search