Max

Not available in this language yet.
Max( value_1, value_2, ... )
Max( value_1, value_2, ... )
Max( value_1, value_2, ... )
Not available in this language yet.
Max( value_1, value_2, ... )

Description

The Max function returns the largest value in a list of values.

The run time of Max is dependent on the number of elements in the underlying set or page — it’s linear, or O(n). For very large sets or pages, executing Max might result in a query timeout error.

To work around this, you may specify a larger query timeout via the driver that you are using.

Parameters

Argument Type Definition and Requirements

value

List of values.

A single value or a list of values.

Returns

A value which is the maximum value from the value list.

Examples

The query below executes an array of independent max operations and returns the results in an array. The result array position matches the execution array position. The top operation in the execution array, max of the values 1, 5, and 22, returns a long value of 22 in the top position of the result array.

Not available in this language yet.
result, err := client.Query(
  f.Arr{
    f.Max(1, 5, 22),
    f.Max(1, 0, 3, -1),
    f.Max(-1, 12, 3, -1),
    f.Max(10)})
[22 3 12 10]
System.out.println(
    client.query(
        Arr(
            Max(Value(1), Value(5), Value(22)),
            Max(Value(1), Value(0), Value(3), Value(-1)),
            Max(Value(-1), Value(12), Value(3), Value(-1)),
            Max(Value(10))
        )
    ).get()
);
[
  22,
  3,
  12,
  10
]
client.query([
  q.Max(1, 5, 22),
  q.Max(1, 0, 3, -1),
  q.Max(-1, 12, 3, -1),
  q.Max(10),
]).then((ret) => console.log(ret))
[ 22, 3, 12, 10 ]
Not available in this language yet.
println(Await.result(
  client.query(
    Arr(
      Max(1, 5, 22),
      Max(1, 0, 3, -1),
      Max(-1, 12, 3, -1),
      Max(10)
    )
  ),
  5.seconds
))
[22, 3, 12, 10]

The following query uses the same approach as the previous query to demonstrate using Max with various types of values:

Not available in this language yet.
  result, err := client.Query(
    f.Arr{
      f.Max("A", "B", "C", "D"),
      f.Max(f.Time("1970-01-01T00:00:00Z"), f.Time("1980-01-01T00:00:00Z")),
      f.Max(f.Date("1970-01-01"), f.Date("1930-01-01")),
      f.Max("A", 1),
      f.Max(true, false),
      f.Max(f.Obj{"x": 10}, f.Obj{"x": 11}),
      f.Max(f.Arr{"A"}, f.Arr{"B"}, f.Arr{"C"}),
      f.Max(f.Arr{"X"}, f.Arr{"A", "B"})})
[D {0 62451129600 <nil>} {0 62135596800 <nil>} A true map[x:11] [C] [X]]
    System.out.println(
        client.query(
            Arr(
                Max(Value("A"), Value("B"), Value("C"), Value("D")),
                Max(Time("1970-01-01T00:00:00Z"), Time("1980-01-01T00:00:00Z")),
                Max(Date("1970-01-01"), Date("1930-01-01")),
                Max(Value("A"), Value(1)),
                Max(Value(true), Value(false)),
                Max(Obj("x", Value(10)), Obj("x", Value(11))),
                Max(Arr(Value("A")), Arr(Value("B")), Arr(Value("C"))),
                Max(Arr(Value("X")), Arr(Value("A"), Value("B")))
            )
        ).get()
    );
["D", 1980-01-01T00:00:00Z, 1970-01-01, "A", true, {x: 11}, ["C"], ["X"]]
client.query([
  q.Max('A', 'B', 'C', 'D'),
  q.Max(q.Time('1970-01-01T00:00:00Z'), q.Time('1980-01-01T00:00:00Z')),
  q.Max(q.Date('1970-01-01'), q.Date('1930-01-01')),
  q.Max('A', 1),
  q.Max(true, false),
  q.Max({ x: 10 }, { x: 11 }),
  q.Max(['A'], ['B'], ['C']),
  q.Max(['X'], ['A', 'B']),
])
.then((ret) => console.log(ret))
[ 'D',
  Time("1980-01-01T00:00:00Z"),
  Date("1970-01-01"),
  'A',
  true,
  { x: 11 },
  [ 'C' ],
  [ 'X' ] ]
Not available in this language yet.
println(Await.result(client.query(
  Arr(
    Max("A", "B", "C", "D"),
    Max(Time("1970-01-01T00:00:00Z"), Time("1980-01-01T00:00:00Z")),
    Max(Date("1970-01-01"), Date("1930-01-01")),
    Max("A", 1),
    Max(true, false),
    Max(Obj("x" -> 10), Obj("x" -> 11)),
    Max(Arr("A"), Arr("B"), Arr("C")),
    Max(Arr("X"), Arr("A", "B"))
  )
),
5.seconds))
["D", 1980-01-01T00:00:00Z, 1970-01-01, "A", true, {x: 11}, ["C"], ["X"]]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!