Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

Primitive value variables

Primitive value variables are used to hold values in procedures or to pass values during procedure execution. Primitive value variables are declared with the keyword VALUE.

Note

The keyword VALUE can also be used to define aggregator value variables and subquery value expressions. When VALUE defines a value variable, it is followed by a variable name. When it is used in a subquery value expression, it is followed by a subquery. The context determines its meaning.

Primitive value variables are applicable to persistent graphs and temporary graphs. They can be defined at any position in a procedure, but they must be defined before they are referenced.

Syntax

primitive_value_variable_definition
VALUE primitive_value_variable TYPED :: value_type = value_expression

primitive_value_variable_definition ::=
    'VALUE' primitive_value_variable (('TYPED' | '::')? value_type)? ('=' value_expression)?

Parameters

primitive_value_variable

The name of the primitive value variable to be defined. primitive_value_variable can be a regular identifier or a delimited identifier enclosed with backticks (`). For more information about identifiers, see Rules for naming identifiers.

value_type

The data type of the value that the variable holds. Supported data types include numeric, string, boolean, temporal, vector, list, set, map, and record. If not specified, the data type is inferred from the value expression.

For more information, see Data types.

value_expression

The value expression that defines the initial value of the variable. The value expression can be a constant, a function call, or a subquery that returns a single value. If not specified, the value of the variable is automatically set to null.

For more information, see Value expressions.

Examples

The following example is based on the Example dataset.

Define primitive value variables

'''
VALUE a INT = 1 
VALUE b::BOOL = true 
VALUE c TYPED STRING = "hello" 
VALUE d DOUBLE = 3.14 
VALUE e LIST<DECIMAL(10, 4)> = [1.1, 2.2] 
VALUE f = RECORD { x: 1, y: "test" } 
VALUE g = DATE '2022-12-31' 
VALUE h = DURATION 'P2M' 
VALUE i = VECTOR<3,FLOAT>([0,1,0]) 
RETURN a, b, c, d, e, f, g, h, i
'''

Return:

+---+------+-------+------+-----------------+--------------+------------+-----+---------------+
| a | b    | c     | d    | e               | f            | g          | h   | i             |
+---+------+-------+------+-----------------+--------------+------------+-----+---------------+
| 1 | true | hello | 3.14 | [1.1000,2.2000] | {x:1,y:test} | 2022-12-31 | P2M | [0.0,1.0,0.0] |
+---+------+-------+------+-----------------+--------------+------------+-----+---------------+

Define primitive value variables with value expressions

'''
VALUE numPerson = VALUE { USE movie MATCH (v:Person) return count(v) GROUP BY() } 
VALUE numMovies = VALUE { USE movie MATCH (t:Movie) return count(t) GROUP BY() }  
USE movie 
LET numObjs = numPerson + numMovies 
MATCH (t:Movie)-[e:WithGenre]->(v2:Genre) WHERE v2.id > 18000 
RETURN numPerson, numMovies, numObjs, v2.id AS genreId
'''

Return:

+-----------+-----------+---------+---------+
| numPerson | numMovies | numObjs | genreId |
+-----------+-----------+---------+---------+
| 4064      | 245       | 4309    | 18385   |
| 4064      | 245       | 4309    | 18385   |
| 4064      | 245       | 4309    | 18385   |
| 4064      | 245       | 4309    | 18385   |
| 4064      | 245       | 4309    | 18305   |
+-----------+-----------+---------+---------+