Query Language Syntax Versions
GSQL has three syntax versions: V3, V2, and V1 (legacy version). In TigerGraph 3.5, the default syntax version was changed to V2. Currently, V2 remains the default syntax version. In a future release, V3 will become the default syntax version. This page provides a summary of the differences between V2 and V3, as well as V1 and V2. It also includes guidance on how to change your V1 query into a V2 query.
Differences between V2 and V3
The table below highlights the differences between V2 and V3, focusing on the FROM
clause.
Note that V3 still supports V2 style syntax, for backward compatibility.
Feature | V2 Style | V3 Style |
---|---|---|
Vertex-Edge-Vertex Markers |
Use |
Use |
Alias Ordering |
Object sets precede aliases: |
Aliases precede object sets: |
Symbols for Edge Direction |
Directionality is applied at the edge-set level. Supports |
Directionality applies to the entire edge pattern. Symbols include |
Edge Direction Syntax |
Supports granular directionality at the individual edge set level, allowing each edge sets in a pattern to have its own direction. |
Directionality is applied globally at the edge pattern level. |
Quantified Multi-Hop Patterns |
V2 uses |
V3 uses |
Filters in Edge Patterns |
Filters are applied outside the |
Filters can also be placed within an edge pattern for more local scope , e.g.,
|
V2 vs. V3 Syntax: Examples and Explanations
-
Vertex-Edge-Vertex Markers:
-
V2 Syntax:
Person -(FRIENDS)- Colleague
-
V3 Syntax:
(Person) -[FRIENDS]- (Colleague)
-
In V3, uses more punctuation in order to be more explicit about vertex and edge patterns.
-
-
Alias Ordering:
-
V2 Syntax:
Person:p -(FRIENDS:f)- Colleague:c
-
V3 Syntax:
(p:Person) -[f:FRIENDS]- (c:Colleague)
-
-
Symbols for Edge Direction:
-
V2 Syntax:
-(FRIENDS>:f)-
-
V3 Syntax:
<-[f:FRIENDS]->
-
V3 directionality is applied globally to the entire edge pattern. V2 directionality applies to each individual edge type, for greater flexibility.
-
-
Filters in Edge Patterns:
-
V2 Syntax: Filtering is applied outside the
FROM
clause using aWHERE
condition:SELECT Person FROM Person -(FRIENDS)- Colleague WHERE FRIENDS.length > 2
-
V3 Syntax: Filters can also be placed within an edge pattern for more local scope:
SELECT Person FROM (Person) -[FRIENDS WHERE FRIENDS.length > 2]-> (Colleague)
-
-
Quantified Multi-Hop Patterns:
-
V2 Syntax:
-(FRIENDS*1..3)->
-
V3 Syntax:
[FRIENDS]->{1,3}
-
Comparing V2 and V3 Edge Directions
In the following table,
-
E1 and E2: These represent directed edge types. A directed edge has a defined direction, such as
Person -> Company
. -
U1 and U2: These represent undirected edge types. An undirected edge does not have a direction and connects vertices symmetrically, such as
Person - Person
. -
Alias (A): The alias is a short name or label given to an edge or vertex for use in queries.
-
Edge Direction:
-
Left (
<
): Represents edges directed towards the starting vertex. -
Right (
>
): Represents edges directed away from the starting vertex. -
Undirected (
~
): Represents edges with no directionality. -
Combination (
<~
,~>
, etc.): Represents edges with a combination of directionality (e.g., left or undirected, right or undirected).
-
Orientation | V2 Syntax | V3 Syntax |
---|---|---|
Pointing Left |
|
|
Pointing Right |
-(E1>:A)- |
|
Undirected |
|
|
Left or Undirected |
|
|
Right or Undirected |
|
|
Any direction or undirected |
or
|
or
|
Differences between V1 and V2
The two tables below summarize the differences between V1 and V2.
Most of the syntactical differences between V1 and V2 lie in the FROM
clause of the SELECT
statement.
Therefore, Table 1 specifically lays out the differences in the FROM
clause.
Other differences are summarized in Table 2.
Feature | V1 | V2 |
---|---|---|
Step vs path pattern |
The keyword For more information, see |
The keyword |
Edge notation |
Edges in a step can optionally have a right arrowhead outside the parentheses.
For example:
|
No arrowheads are allowed outside the parentheses.
If an edge type is directed, the edge notation must have arrowheads inside the parentheses to indicate direction.
For example:
|
Traversal direction |
The traversal action is from left to right, and the notation uses either a rightward facing arrowhead or no arrowhead to depict a connection. |
The traversal direction is under the control of the query writer, with arrowheads on each edge set to show the direction. |
Source vertex set |
The source vertex set in a step in the |
The source vertex set path pattern in |
Feature | V1 | V2 |
---|---|---|
|
|
|
Not supported. |
Supported. |
|
Data modification statements |
|
|
Changing a query from V1 to V2
This section provides you with instructions to convert a V1 query into a V2 query.
GSQL can detect the syntax version of the query automatically, so there is no need to modify your queries from V1 to V2.
-
Delete, move, or add arrowheads in the
FROM
clause.-
If the edge is undirected, delete the arrowhead outside parentheses in the
FROM
clause.-
For example
Source:s -(Friend:e)-> :t
becomesSource:s -(Friend:e)- :t
-
-
If the edge is directed, move the arrowheads into the parentheses after the edge type. If there is no arrowhead, you must add one after the edge type.
-
For example,
Source:s -(Is_Located_In:e)-> :t
becomesSource:s -(Is_Located_In>:e)- :t
-
This is the most common incompatibility issue between a query written in V1 and V2. Most V1 queries can run smoothly in V2 after the arrowheads are deleted.
-
-
Check for
POST-ACCUM
clauses that aren’t bound to one vertex alias or are bound to more than one vertex alias.-
In V2, every
POST-ACCUM
clause must reference one vertex alias. If your V1 query has aPOST-ACCUM
clause that reference multiple vertex aliases, you need to break thePOST-ACCUM
clause into multiplePOST-ACCUM
clauses, with each clause referencing one vertex alias only.
-
Since a SELECT
statement can only perform one hop in V1, you may have had to write multiple SELECT
statements in order to write a multi-hop query.
With pattern matching in V2, you may choose to rewrite the query to use a single SELECT
statement to perform multiple hops.