Skip to content
Permalink
Browse files
Add PG/PSQL documentation
  • Loading branch information
JoshInnis committed Jan 17, 2022
1 parent 3d3ae86 commit 080324d81ecb4310ba5fb29ac84f10c4a160c05e
Showing 1 changed file with 61 additions and 6 deletions.
@@ -2,9 +2,35 @@

Cypher commands can be run in [PL/pgSQL](https://www.postgresql.org/docs/11/plpgsql-overview.html) functions without restriction.

Data Setup
```
CREATE FUNCTION get_all_vertices()
RETURNS TABLE(vertex ag_catalog.agtype)
SELECT *
FROM cypher('imdb', $$
CREATE (toby:actor {name: 'Toby Maguire'}),
(tom:actor {name: 'Tom Holland'}),
(willam:actor {name: 'Willam Dafoe'}),
(robert:actor {name: 'Robert Downey Jr'}),
(spiderman:movie {title: 'Spiderman'}),
(no_way_home:movie {title: 'Spiderman: No Way Home'}),
(homecoming:movie {title: 'Spiderman: Homecoming'}),
(ironman:movie {title: 'Ironman'}),
(tropic_thunder:movie {title: 'Tropic Thunder'}),
(toby)-[:acted_in {role: 'Peter Parker', alter_ego: 'Spiderman'}]->(spiderman),
(willam)-[:acted_in {role: 'Norman Osborn', alter_ego: 'Green Goblin'}]->(spiderman),
(toby)-[:acted_in {role: 'Toby Maguire'}]->(tropic_thunder),
(robert)-[:acted_in {role: 'Kirk Lazarus'}]->(tropic_thunder),
(robert)-[:acted_in {role: 'Tony Stark', alter_ego: 'Ironman'}]->(homecoming),
(tom)-[:acted_in {role: 'Peter Parker', alter_ego: 'Spiderman'}]->(homecoming),
(tom)-[:acted_in {role: 'Peter Parker', alter_ego: 'Spiderman'}]->(no_way_home),
(toby)-[:acted_in {role: 'Peter Parker', alter_ego: 'Spiderman'}]->(no_way_home),
(willam)-[:acted_in {role: 'Norman Osborn', alter_ego: 'Green Goblin'}]->(no_way_home)
$$) AS (a agtype);
```

Function Creation
```
CREATE OR REPLACE FUNCTION get_all_actor_names()
RETURNS TABLE(actor agtype)
LANGUAGE plpgsql
AS $BODY$
BEGIN
@@ -13,14 +39,43 @@ BEGIN
RETURN QUERY
SELECT *
FROM ag_catalog.cypher('graph_name', $$
MATCH (v)
RETURN v
$$) AS (a ag_catalog.agtype);
FROM ag_catalog.cypher('imdb', $$
MATCH (v:actor)
RETURN v.name
$$) AS (a agtype);
END
$BODY$;
```

Query:
```
SELECT * FROM get_all_actor_names();
```

Results
<table>
<tr>
<td><strong>title</strong>
</td>
</tr>
<tr>
<td>"Toby Maguire"</td>
</tr>
<tr>
<td>"Tom Holland"</td>
</tr>
<tr>
<td>"Willam Dafoe"</td>
</tr>
<tr>
<td>"Robert Downey Jr"</td>
</tr>
<tr>
<td>4 row(s) returned
</td>
</tr>
</table>

```
Developer's Note:

0 comments on commit 080324d

Please sign in to comment.