Published using Google Docs
GQL on one page: DDL, DML, GPML
Updated automatically every 5 minutes

GQL on one page  DDL, DML, GPML

The following near-minimal example[1] omits session and transaction control statements, and only shows directed edges (although GQL does support undirected edges).

An administrator creates a graph type inside a schema, inside a hierarchy of catalog directories, using type patterns to specify the types of node and edge which a graph can contain. They then create a graph of that type.

AT /"com.bank"/control
CREATE GRAPH TYPE fraud_GT { // DDL

     (customer :Customer => {id::STRING, name::STRING}),

     (account :Account => {no::STRING, type::STRING }),

     (customer)-[:HOLDS]->(account),

     (account)-[:TRANSFER {amount::INTEGER}]->(account)

}

CREATE GRAPH fraud TYPED fraud_GT // TYPED synonym for ::

A user states that they want to operate on the named graph, and inserts four nodes and three edges, which must be of types permitted in the graph type, using insert patterns.

USE /* graph */ /"com.bank"/control/fraud

INSERT // DML

     (c1 :Customer {id: 'AB23', name: 'Doe'}),

     (c2 :Customer {id: 'CH45', name: 'Reiss'}),

     (a1 :Account {no: '25673890', type: 'C'}),

     (a2 :Account {no: '05663981', type: 'C'}),

     (c1)-[:HOLDS]->(a1), (c2)-[:HOLDS]->(a2),

     (a1)-[:TRANSFER {amount: 5000}]->(a2)

Another user, using the same graph, processes a MATCH query (specifying a graph pattern, here made up of a single path pattern) which selects all the transfer paths in the graph, and then RETURNs some values of their elements' properties, as an output table.

AT CURRENT_SCHEMA USE fraud // session schema already set

MATCH // GPML – “Graph Pattern Matching Language” (DQL)

     (c1 :Customer)-[:HOLDS]->(a1 :Account)

         -[t :TRANSFER]->

     (a2 : Account)<-[:HOLDS]-(c2 :Customer)

RETURN

    c1.name, a1.no, t.amount, c2.name, a2.no

/*

    'Doe', '25673890', 5000, 'Reiss', '05663981'

    1 row returned

*/


[1] Copyright © 2024 Alastair Green. alastair.green@ {ldbcouncil.org | graphres.org} 

April 2024. A Linked Data Benchmark Council documentary contribution. License granted: CC-BY 4.0.

Thanks to Hannes Voigt and Keith Hare for comments and suggestions. ›