Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/value-variable/ Documentation version: v5.3.2 # 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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/agg/) and [subquery value expressions](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/subquery/). 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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph/create/) and [temporary graphs](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/ddl/graph-projection/create/). They can be defined at any position in a procedure, but they must be defined before they are referenced. ## Syntax diagramsource primitive_value_variable_definition ```` 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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/#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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/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](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/#value_expressions). ## Examples The following example is based on the [Example dataset](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/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 = [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 | +-----------+-----------+---------+---------+ ````