Function
compare — compare values even when types vary
Synopsis
compare(a: any, b: any [, nullsMax: bool]) -> int64
Description
The compare function returns an integer comparing two values. The result will
be 0 if a is equal to b, +1 if a is greater than b, and -1 if a is less than b.
compare differs from comparison expressions in that it will work for any type (e.g., compare(1, "1")).
Values are compared via byte order. Between values of type string, this is
equivalent to C/POSIX collation
as found in other SQL databases such as Postgres.
Note
A future version of SuperSQL will collate values polymorphically using a well-defined total order that embodies the super-structured type order.
nullsMax is an optional value (true by default) that determines whether null
is treated as the minimum or maximum value.
Examples
# spq
values compare(a, b)
# input
{a:2,b:1}
{a:2,b:"1"}
# expected output
1
-1