Min

Min( value_1, value_2, ... )
Min( value_1, value_2, ... )
Min( value_1, value_2, ... )
Min( value_1, value_2, ... )
min( value_1, value_2, ... )
Min( value_1, value_2, ... )

Description

The Min function returns the smallest value in a list of values.

Types have an order of precedence. When comparing values of different types, they are ranked in the following order, from least to greatest.

  1. Number (integers and decimals: 0.5 < 1 < 1.5 < 2)

  2. Byte

  3. String

  4. Array (ordered lexically, like strings)

  5. Object (ordered lexically, like strings)

  6. Reference

  7. Timestamp

  8. Date

  9. Boolean (false < true)

  10. Null

With this precedence, Numbers are always smaller than Strings.

The run time of Min 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 Min 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 minimum value from the value list.

Examples

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

Value result = await client.Query(
    Arr(
        Min(1, 5, 22),
        Min(1, 0, 3, -1),
        Min(-1, 12, 3, -1),
        Min(Arr(10))
    )
);

Console.WriteLine(result);
Arr(LongV(1), LongV(-1), LongV(-1), LongV(10))
result, err := client.Query(
	f.Arr{
		f.Min(1, 5, 22),
		f.Min(1, 0, 3, -1),
		f.Min(-1, 12, 3, -1),
		f.Min(f.Arr{10}),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[1 -1 -1 10]
System.out.println(
    client.query(
        Arr(
            Min(Value(1), Value(5), Value(22)),
            Min(Value(1), Value(0), Value(3), Value(-1)),
            Min(Value(-1), Value(12), Value(3), Value(-1)),
            Min(Arr(Value(10)))
        )
    ).get());
[1, -1, -1, [10]]
client.query(
  [
    q.Min(1, 5, 22),
    q.Min(1, 0, 3, -1),
    q.Min(-1, 12, 3, -1),
    q.Min([10]),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
[ 1, -1, -1, 10 ]
result = client.query(
  [
    q.min(1, 5, 22),
    q.min(1, 0, 3, -1),
    q.min(-1, 12, 3, -1),
    q.min([10]),
  ]
)
print(result)
[1, -1, -1, 10]
println(Await.result(
    client.query(
        Arr(
            Min(1, 5, 22),
            Min(1, 0, 3, -1),
            Min(-1, 12, 3, -1),
            Min(Arr(10))
        )
    ),
    5.seconds
))
[1, -1, -1, 10]

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

Value result = await client.Query(
    Arr(
        Min("A", "B", "C", "D"),
        Min(10, 11, "A"),
        Min(Time("1970-01-01T00:00:00Z"), Time("1980-01-01T00:00:00Z")),
        Min(Date("1970-01-01"), Date("1930-01-01")),
        Min("A", 1),
        Min(true, false),
        Min(Obj("x", 10), Obj("x", 11)),
        Min(Arr("A"), Arr("B"), Arr("C")),
        Min(Arr("X"), Arr("A", "B"))
    )
);

Console.WriteLine(result);
Arr(StringV(A), LongV(10), FaunaTime(1970-01-01T00:00:00Z), FaunaDate(1930-01-01 12:00:00 AM), LongV(1), BooleanV(False), ObjectV(x: LongV(10)), Arr(StringV(A)), Arr(StringV(A), StringV(B)))
result, err := client.Query(
	f.Arr{
		f.Min("A", "B", "C", "D"),
		f.Min(10, 11, "A"),
		f.Min(f.Time("1970-01-01T00:00:00Z"), f.Time("1980-01-01T00:00:00Z")),
		f.Min(f.Date("1970-01-01"), f.Date("1930-01-01")),
		f.Min("A", 1),
		f.Min(true, false),
		f.Min(f.Obj{"x": 10}, f.Obj{"x": 11}),
		f.Min(f.Arr{"A"}, f.Arr{"B"}, f.Arr{"C"}),
		f.Min(f.Arr{"X"}, f.Arr{"A", "B"}),
	})

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[A 10 {0 62135596800 <nil>} {0 60873292800 <nil>} 1 false map[x:10] [A] [A B]]
System.out.println(
    client.query(
        Arr(
            Min(Value("A"), Value("B"), Value("C"), Value("D")),
            Min(Value(10), Value(11), Value("A")),
            Min(Time("1970-01-01T00:00:00Z"), Time("1980-01-01T00:00:00Z")),
            Min(Date("1970-01-01"), Date("1930-01-01")),
            Min(Value("A"), Value(1)),
            Min(Value(true), Value(false)),
            Min(Obj("x", Value(10)), Obj("x", Value(11))),
            Min(Arr(Value("A")), Arr(Value("B")), Arr(Value("C"))),
            Min(Arr(Value("X")), Arr(Value("A"), Value("B")))
        )
    ).get()
);
["A", 10, 1970-01-01T00:00:00Z, 1930-01-01, 1, false, {x: 10}, ["A"], ["A", "B"]]
client.query(
  [
    q.Min('A', 'B', 'C', 'D'),
    q.Min(10, 11, 'A'),
    q.Min(q.Time('1970-01-01T00:00:00Z'), q.Time('1980-01-01T00:00:00Z')),
    q.Min(q.Date('1970-01-01'), q.Date('1930-01-01')),
    q.Min('A', 1),
    q.Min(true, false),
    q.Min({ x: 10 }, { x: 11 }),
    q.Min(['A'], ['B'], ['C']),
    q.Min(['X'], ['A', 'B']),
  ]
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
[
  'A',
  10,
  Time("1970-01-01T00:00:00Z"),
  Date("1930-01-01"),
  1,
  false,
  { x: 10 },
  [ 'A' ],
  [ 'A', 'B' ]
]
result = client.query(
  [
    q.min("A", "B", "C", "D"),
    q.min(10, 11, "A"),
    q.min(q.time("1970-01-01T00:00:00Z"), q.time("1980-01-01T00:00:00Z")),
    q.min(q.date("1970-01-01"), q.date("1930-01-01")),
    q.min("A", 1),
    q.min(True, False),
    q.min({"x": 10}, {"x": 11}),
    q.min(["A"], ["B"], ["C"]),
    q.min(["X"], ["A", "B"]),
  ]
)
print(result)
['A', 10, FaunaTime('1970-01-01T00:00:00Z'), datetime.date(1930, 1, 1), 1, False, {'x': 10}, ['A'], ['A', 'B']]
println(Await.result(
    client.query(
        Arr(
            Min("A", "B", "C", "D"),
            Min(10, 11, "A"),
            Min(Time("1970-01-01T00:00:00Z"), Time("1980-01-01T00:00:00Z")),
            Min(Date("1970-01-01"), Date("1930-01-01")),
            Min("A", 1),
            Min(true, false),
            Min(Obj("x" -> 10), Obj("x" -> 11)),
            Min(Arr("A"), Arr("B"), Arr("C")),
            Min(Arr("X"), Arr("A", "B"))
        )
    ),
    5.seconds
))
["A", 10, 1970-01-01T00:00:00Z, 1930-01-01, 1, false, {x: 10}, ["A"], ["A", "B"]]

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!