Closed matthew-wozniczka closed 7 years ago
I intended a simplified version of ANSI SQL comparison rules, but perhaps I over-simplified. I'll have to review ANSI and we can decide if we want to follow those semantics or not.
Yes; looks like I oversimplified. Here is an excerpt of the actual rules from SQL2015:
If the declared types of XV and YV are row types with degree N, then let Xi, 1 (one) ≤ i ≤ N,
denote a
The result of X
Updated section to read:
Two structured values are comparable if, and only if, they have the same structural members. For two structured values SV1 and SV2. SV1 = SV2 is true if every member m1 in SV1 equals the corresponding member m2 in SV2, otherwise SV1 = SV2 is false. SV1 < SV2 is true if SV1 != SV2 and every member m1 in SV1 is less than or equal to the corresponding member m2 in SV2, otherwise SV1 < SV2 is false.
That's slightly different than the rules you gave from SQL2015 - for your updated rules, (0, 1) would not be considered less than (0, 0), where in SQL2015 it would. Is that what you meant?
Section 3.10.2 (Query Extensions for Structured Columns) states the following:
I don't think this is a good definition, as it will not behave how people expect:
A != B
will evaluate tofalse
ifA = (1, 2, 3)
andB = (1, 200, 300)
because it is not the case that<first element of A> != <first element of B>
A == B
XORA != B
.It's also a bit unfortunate that
<
,<=
,>
, and>=
become not very useful under that definition (I think using lexicographical order would useful, if we wanted to define them at all). It may make sense to not even define these operators for structured types, or leave them implementation defined, to reduce burden on the implementation.