Expressions overview¶
An expression is, in general, a declaration of constants, variables, operators, function calls and many others that evaluate to a specific value. In GQL, there are many forms of expressions, such as function call expressions that invoke functions, label expressions that match one or more labels of a graph element, value expressions that evaluate to values or constants, and so on. The sections below show how to use these expressions in GQL queries.
Functions¶
A function is a command that maps input arguments to return values according to pre-defined algorithms. In this documentation, we uniquely introduce and identify a function using a function signature for explanatory purposes.
GQL provides a set of built-in functions that you can use in your queries. You can run the command SHOW FUNCTIONS to view all the functions.
The following are the types of functions supported by GQL:
- Math functions
- Aggregate functions
- String functions
- Date and time functions
- List functions
- Graph functions
- Lambda functions
- Vector functions
- Spatial functions
Function signatures¶
The function signature defines the function name, the names and data types of arguments, and the data type of the return value.
The following example shows the function signature of the element_id() function:
element_id(n: NODE) -> INT64
element_idis the function name.nis the name of the argument, which can be the return value of a value expression.NODEis the data type of the argument. You can find the supported data types for each function's argument by using the commandSHOW FUNCTION <function_name>.UINT64is the data type of the return value. You can find the data type of the return value by using the commandSHOW FUNCTION <function_name>.- If the function is variadic, the last input parameter is followed by the ellipsis (
...) symbol.
Null behavior¶
The null behavior defines how a function behaves when any of its arguments are NULL. In GQL, the following null behaviors are defined:
- default: The function returns a
NULLvalue result if any of its arguments areNULL. - ignore: The function ignores
NULLin its arguments. - error: The function returns an error if any of its arguments are
NULL. - general: The function returns a function-specific result if any of its arguments are
NULL.
For the null behavior of each function, see the corresponding topic.
Operators¶
An operator is a symbol or keyword that performs operations on one or more operands. For more information about the operators supported by GQL, see Operators.
Predicates¶
A predicate specifies a condition that evaluates to a boolean value. GQL supports the following types of predicates:
- Comparison predicate
- EXISTS predicate
- Null predicate
- Labeled predicate
- ALL_DIFFERENT predicate
- SAME predicate
Value expressions¶
A value expression specifies a value or a constant. GQL supports the following types of value expressions:
- Aggregate value expression: returns a single value that is calculated from multiple values.
- Variable value expression: returns the value of a variable.
- Case value expression: returns a value based on a set of conditions.
- Constant value expression: returns a constant value.
- Construct value expression: constructs a value from a set of values.
- Function value expression: returns the value of a function.
- Logical value expression: returns a boolean value.
- Property value expression: returns the value of a property.
- Subquery value expression: returns the value of a subquery.
- Cast value expression: converts a value to a different data type.
- Lambda value expression: returns the value of a lambda function.
Label expressions¶
A label expression specifies one or more labels that are used to identify a graph element. For more information, see Label expressions.