TMQL Issue: != is not not ==, or is it?

One of the TMQL issues raises the question why there is no != operator when there is a == comparison.

In the following my attempt to explain the reasoning behind that decision. As always, feel free to comment.

Let us look at the simple query expression

select $p / name
where
   $p /
shoesize >= 42

Apart from trying to solve the answer to Life, the Universe, and Everything it also gives us the names of all people with a shoesize of at least 42.

That innocuously looking query is actually not completely trivial. In theory, a topic may have any number of shoesize occurrences. So the expression $p / shoesize will actually return a list and not just a single value.

If we compare now that list with the single value 42, then what the processor will do is to find one element in the list satisfying the comparison.

This is called the implicit exists semantics and it is everywhere in TMQL, just to make life easier as it incorporates what normally the user expectation is.

What is works for >= also works for other comparison operators, such as the ==:

select $p / name
where
   $p /
shoesize == 42

So far so good.

Now let us try to define what a newly introduced != could mean:

select $p / name
where
   $p /
shoesize != 42

Does it mean

  • there is one shoesize which is not 42 ?
  • all shoesizes are not equal 42 ?
  • there must exist at least one shoesize, but if these existed, none of them is 42 ?
  • the number of shoesize occurrences is not 42?

Each of the above interpretation are somewhat plausible, some more plausible than others. But none is the obvious choice.

Hence the decision not to define a != and instead let the user write:

select $p / name
where
   not $p /
shoesize == 42

Here it is clear (I think, I hope) that it means:

no shoesize shall exist which equals 42.

Work supported by the Austrian Research Centers.

Posted In