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

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

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

Length

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

Length( value )
length( value )
Length( value )
Length( value )
Length( value )
Length( value )

Description

The length function returns the number of characters in the provided string.

Although we mention characters, technically, we are talking about code points. In Unicode, a code point is usually, but not always, a character. Code points can sometimes represent single characters, but can also represent formatting and other non-alphanumeric characters.

For example, the character é can be the single character "e" that includes an acute accent (U+00E9), or it could be displayed as a single character but be composed of an "e" (U+0065) and a "combining" acute accent (U+0301). Visually, you cannot distinguish between the two.

Parameters

Parameter Type Definition and Requirements

value

String

The String that should have its characters counted.

Returns

An integer that reports the number of characters in the string.

Examples

client.query(
  [
    q.Length('fire'),
    q.Length('fire and fireman'),
    q.Length(''),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 4, 16, 0 ]
result = client.query(
  [
    q.length("fire"),
    q.length("fire and fireman"),
    q.length(""),
  ]
)
print(result)
[4, 16, 0]
result, err := client.Query(
	f.Arr{
		f.Length("fire"),
		f.Length("fire and fireman"),
		f.Length(""),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[4 16 0]
try
{
    Value result = await client.Query(
        Arr(
            Length("fire"),
            Length("fire and fireman"),
            Length("")
        )
    );

    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(LongV(4), LongV(16), LongV(0))
System.out.println(
    client.query(
        Arr(
            Length("fire"),
            Length("fire and fireman"),
            Length("")
        )
    ).get());
[4, 16, 0]
[
  Length('fire'),
  Length('fire and fireman'),
  Length(''),
]
[ 4, 16, 0 ]
Query metrics:
  •    bytesIn:  63

  •   bytesOut:  21

  • 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!