gsql/ openCypher in GSQL
Last Updated: October 20, 2018Leveraging the popular openCypher query language within TigerGraph's GSQL engine.
openCypher in GSQL
TigerGraph supports openCypher, a declarative query language for property graphs, by embedding it directly within GSQL queries. This allows developers to use familiar MATCH patterns while benefiting from GSQL's performance.
1. Core Supported Clauses
You can use the following openCypher clauses inside GSQL queries:
- MATCH: Specify patterns to search for.
- OPTIONAL MATCH: Patterns that may or may not exist (returns null for missing parts).
- WITH: Pipe results from one pattern to the next.
- RETURN: Define the final output.
- WHERE: Filter results based on attributes or relationships.
2. Key Differences: Schema-First vs. Schema-Optional
While standard openCypher is "schema-optional," TigerGraph's implementation is schema-first.
| Feature | openCypher (Neo4j) | openCypher in GSQL |
|---|---|---|
| Attributes | Optional; can vary per node. | Required; must follow vertex/edge type. |
| Missing Data | Returns NULL. | Ignores the vertex/edge entirely. |
| Performance | Flexible but can be slow. | Compiled to machine code for speed. |
3. Example Usage
You can wrap openCypher logic within a GSQL query block:
gsqlterminalCREATE QUERY find_friends(STRING person_name) { MATCH (p:Person {name: person_name})-[:FRIEND]-(f:Person) RETURN f.name AS friend_name; }
4. Limitations
- No Path Variables: Assigning a path to a variable (e.g.,
p = (a)-[r]->(b)) is generally restricted in older versions. - Strict Connectivity: Patterns in a
MATCHclause must typically be connected via edges or shared variables. - GSQL-Only Operations: Complex accumulators and control flow (loops) still require GSQL syntax outside the
MATCHblock.
[!TIP] Use
MATCHfor simple pattern discovery and switch to native GSQLSELECTstatements for deep, high-performance graph analytics.
On this page
TigerGraph Book
v1.0 Curated