MironAtHome commented on issue #1933:
URL: https://github.com/apache/age/issues/1933#issuecomment-2212339556

   > Hello!
   > 
   > I have a pretty basic cypher function whose result I'd like to assign to a 
pgsql variable.
   > 
   > Here is the mentioned query.
   > 
   > ```sql
   > LOAD 'age';
   > SET search_path = ag_catalog, "$user", public;
   > 
   > SELECT exists
   > FROM cypher('test_graph', $$
   >     MATCH (n:Node)
   >     RETURN exists((n)-[:START]->())
   > $$) as (exists agtype);
   > ```
   > 
   > I'm stumped.
   > 
   > In a way, I hope that the answer is obvious, but not too obvious!
   
   Here is example:
   ```
   LOAD 'age';
   SET search_path = ag_catalog, "$user", public;
   DO
   $RUN$
   DECLARE
       Output_Var jsonb;
   BEGIN
   LOAD 'age';
   SET search_path = ag_catalog, "$user", public;
   
   SELECT INTO Output_Var
            array_to_json(array_agg(jsonb_build_object(
           'existscheck', t.existscheck
          , 'key', t.id)))
   FROM cypher('test_graph', $$
       MATCH (n:Node)
       OPTIONAL MATCH (n)-[e:START]->(u)
       WITH ag_catalog.agtype_to_bool(exists((n)-[e]->(u))) AS existscheck, 
id(n) as id
       RETURN existscheck, id
      ORDER BY id ASC
      LIMIT 10
   $$) as t(existscheck boolean, id agtype);
   RAISE NOTICE 'Output_Var : %', Output_Var;
   END;
   $RUN$;
   ```
   
   Hope it helps.
   --cheers


-- 
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: dev-unsubscr...@age.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to