skip to Main Content

I’m trying to implement two sequential pairs of (MATCH, SET) as in following code, please note that the example below can be replaced with one (MATCH, SET) pair as the example is just for demonstration purposes, but in my situation two sequential pairs is a must:

SELECT * FROM cypher('test', $$
MATCH (a: person {name:'yousef'})  SET a.name = 'yousef222' RETURN n.name MATCH(b:person {name: 'mostafa'}) SET b.name = 'mostafa222' RETURN a.name ,b.name
$$) as (a_name agtype, b_name agtype);
                                                             

when I run the query I get the following error:

ERROR:  syntax error at or near "MATCH"
LINE 2: ...name:'hla'})  SET n.name = 'hlaaaa' RETURN n.name MATCH(b:pe...
                                                             ^

How can I resolve the issue while maintaining the two sequential pairs?

3

Answers


  1. You need to use the WITH...AS clause like so:

    SELECT * FROM cypher ('test', $$ MATCH (a: person {name: 'yousef'}) 
    SET a.name = 'yousef222' 
    WITH a.name 
    AS a_name 
    MATCH (b: person {name: 'mostafa'}) 
    SET b.name = 'mostafa222' 
    RETURN a_name, b.name $$) 
    AS (a_name agtype, b_name agtype);
    
    Login or Signup to reply.
  2. The synatax error you encountered was because you used n.name and n was not defined in the query,
    but you can implement two sequential pairs of (MATCH/SET) by modifying your query as follows:

    SELECT * FROM cypher('test', $$
    MATCH (a: person {name:'yousef'})
    MATCH (b:person {name: 'mostafa'})
    SET a.name = 'yousef222', b.name = 'mostafa222'
    RETURN a.name, b.name
    $$) AS (a_name agtype, b_name agtype);
    

    Hope this helps.

    Login or Signup to reply.
  3. Here issue is with query that you are trying to use MATCH-SET pair in a single pair. You can only have single MATCH clause for single return therefore split your query in two separate cypher.

    SELECT * FROM cypher ("name_here", $$ MATCH (a:person{name: "your_name"})
    
     SET  a.name= "name_here" RETURN n.name $$ ) as (a_name agtype)'
    

    similar write another one like this

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