diff --git a/lib/src/sql/value/compare.rs b/lib/src/sql/value/compare.rs index bf1eb562..0b2f1b24 100644 --- a/lib/src/sql/value/compare.rs +++ b/lib/src/sql/value/compare.rs @@ -46,7 +46,7 @@ impl Value { (None, Some(_)) => Some(Ordering::Less), (_, _) => Some(Ordering::Equal), }, - Part::Last => match (a.first(), b.first()) { + Part::Last => match (a.last(), b.last()) { (Some(a), Some(b)) => a.compare(b, path.next(), collate, numeric), (Some(_), None) => Some(Ordering::Greater), (None, Some(_)) => Some(Ordering::Less), @@ -192,4 +192,13 @@ mod tests { let res = one.compare(&two, &idi, false, false); assert_eq!(res, Some(Ordering::Greater)); } + + #[test] + fn compare_last() { + let idi = Idiom::parse("test[$]"); + let one = Value::parse("{ test: [1,5] }"); + let two = Value::parse("{ test: [2,4] }"); + let res = one.compare(&two, &idi, false, false); + assert_eq!(res, Some(Ordering::Greater)) + } }