Graph Studio Tutorial (5/6)

PGQL — Basic Graph Patterns

Pablo Sierra
3 min readAug 17, 2022

Previous chapter,

In previous chapter We created our first graph using the python API, but, how we can query it?, well, the answer you could suppose is use PGQL.

← Build your First Graph using the Python API — |

PGQL

Property Graph Query Language (PGQL) is SQL-like graph query language based on SQL constructs and functions to create, select, modify and drop Graphs.

With PGQL you can build, update a search for Cycles, Paths and Patterns in the graphs and make easy write graph queries for SQL developers.

The very basic could be:

Syntax

SQL constructs: SELECT, FROM, WHERE, ORDER BY.

SQL functions : SUM, AVG, MIN, MAX.

Specifications

NODE: Symbols () or (n) or (node) represents nodes, n and node are variables.

EDGES: Symbols [] or [e] or [edge] represents edges, e and edge are variables.

DIRECTED EDGE: Symbols <- or -> represent de edge path with a specific way.

UNIDIRECTED EDGE: Symbol represent de edge path with any way.

LABEL SPECIFICATION: Symbol : specify a label (type of vertex/edge) Ex: (v:PERSON), [e:TRANSFER].

PATH: / */Existence of a path (zero or more hops), use / +/ for one or more paths

Now, in order to use PGQL We need create a new cell type who start with %pgql-pgx.

The line of code inside is created by default and for our example is nearly fine.

Before run, you must change the GRAPH_NAME for graph created in the previous chapter and then click on the run button.

And woohoo our first PGQL query over our first graph is completed! yeah!.

PGQL basic examples

Really, the PGQL has a lot of variations and mus be mastered, but, some fundamental queries could be:

To take away:

First, the variables names could be any, for example, node and edge or shorthand as n1, e, n2.

Second, to run PGQL the cell must be start with %pgql-pgx.

Third, you can run only one of the query at time.

For example,

As you can see in the image above, to customize your notebooks, one tip is change the cell size clicking on the tool button who appears in the upper right side of every cell.

And is possible add a title too, changing the visibility options.

Finally, is a good practice close you graph:

%python-pgx
graph.close()

What next?

In this chapter, We cover the very basic options and now we can explore more advanced features in our final chapter using graph’s labels and properties.

Final chapter,

| — Labels and Properties→

--

--

Pablo Sierra

Solution Architect with expertise in artificial intelligence (AI), analytics, and Oracle Cloud solutions.