FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

Var

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Var( name )
let name
Var( name )
Var( name )
Var( name )

Description

The Var statement evaluates and returns the value stored in a named variable. The Var statement can only be used inside other statements, such as Let or Lambda.

When _ (underscore) is used to define an item in a parameter array for a Lambda , it is not a variable; it is a placeholder for a parameter that should be ignored. You cannot access an ignored parameter with Var('_'). For example, this is invalid:

Map(
  [
    ['a', 1],
    ['b', 2]
  ],
  Lambda(
    ["name", "_"],
    {
      name: Var("name"),
      number: Var("_")
    }
  )
)
Error: invalid expression
{
  errors: [
    {
      position: [
        'map',
        'expr',
        'object',
        'number'
      ],
      code: 'invalid expression',
      description: "Variable '_' is not defined."
    }
  ]
}

You can use _ as a field name in a document or object, such as in a Let binding. For example, this is valid:

Let({ _: 'bar' }, Var('_'))
'bar'

Parameters

Parameter Type Definition and Requirements

name

String

The name of the variable whose value should be returned.

Returns

The Value stored in the variable identified by name.

Examples

The following query defines two variables in a Let statement. The first variable "x" contains the value 1 and the second variable "y" contains the value 2. When the simple "in" expression is executed, it returns the value stored in the variable "x".

client.query(
  q.Let({ x: 1, y: 2 }, q.Var('x'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
1
result = client.query(
  q.let({"x": 1, "y": 2}, q.var("x"))
)
print(result)
1
result, err := client.Query(
	f.Let().Bind(
		"x", 1).Bind(
		"y", 2).In(
		f.Var("x")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
1
try
{
    Value result = await client.Query(
        Let("x", 1, "y", 2).In(Var("x"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
LongV(1)
Let({ x: 1, y: 2 }, Var('x'))
1
Query metrics:
  •    bytesIn:  42

  •   bytesOut:  14

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 3ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!