SQL
Comparison and Ordering
The `STRUCT` type can be compared using all the [comparison operators](#docs:sql:expressions:comparison_operators).
These comparisons can be used in [logical expressions](#docs:sql:expressions:logical_operators)
such as `WHERE` and `HAVING` clauses, and return [`BOOLEAN` values](#docs:sql:data_types:boolean).  
For comparisons, the keys of a `STRUCT` have a fixed positional order, from left to right.
Comparisons behave the same as row comparisons, therefore, matching keys must be at identical positions.  
Specifically, for any `STRUCT` comparison, the following rules apply:  
* **Equality.** `s1` and `s2` are equal, if all respective values are equal.
* **Less Than**. For the first index `i` where `s1.value[i] != s2.value[i]`:
If `s1.value[i] < s2.value[i]`, `s1` is less than `s2`.  
`NULL` values are compared following PostgreSQL's semantics.
Lower nesting levels are used for tie-breaking.  
Here are some queries returning `true` for the comparison.  
```sql
SELECT {'k1': 2, 'k2': 3} < {'k1': 2, 'k2': 4} AS result;
```  
```sql
SELECT {'k1': 'hello'} < {'k1': 'world'} AS result;
```  
These queries return `false`.  
```sql
SELECT {'k2': 4, 'k1': 3} < {'k2': 2, 'k1': 4} AS result;
```  
```sql
SELECT {'k1': [4, 3]} < {'k1': [3, 6, 7]} AS result;
```  
These queries return `NULL`.  
```sql
SELECT {'k1': 2, 'k2': 3} < {'k1': 2, 'k2': NULL} AS result;
```  
This query returns a `Binder Error` because the keys do not match positionally.  
```sql
SELECT {'k1': 2, 'k2': 3} < {'k2': 2, 'k1': 4} AS result;
```  
```console
Binder Error: Cannot compare values of type STRUCT(k1 INTEGER, k2 INTEGER)
and type STRUCT(k2 INTEGER, k1 INTEGER) - an explicit cast is required
```