Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative comparison operators #2

Open
grimblefritz opened this issue May 22, 2015 · 3 comments
Open

Relative comparison operators #2

grimblefritz opened this issue May 22, 2015 · 3 comments

Comments

@grimblefritz
Copy link

Currently there are three selection modes - name exists, name=value, or the complement thereof. I propose adding relative comparisons of the following types:

< <= >= >

These should be constrained to either integer or float values. For example:

mem>64

I cannot at the moment think of a float value. I think automatic casting is probably overkill and (personally) would think integer is sufficient.

In the event a non-integer value is supplied, there are a few possibilities:

  • Treat the value as zero, so a zero in the database would match
  • Treat the value as null/undefined, so nothing in the database would match

I prefer the second option, since a non-integer string is an error.

Note that, if the NOT operator previous suggested is implemented, then you could get by with implementing only < and >.

  • Instead of <= you would use !>
  • Instead of >= you would use !<

That said, I think <= and >= are a bit more mainstream and definitely easier to read and understand.

@wlschwartz
Copy link

Thanks, Grimble! Expanding these selection modes will improve usage. I'd support...

@elstak
Copy link

elstak commented Jun 1, 2015

The 'mem' example perfectly justifies the request for enhancement. I would not agree with returning an error with non-numeric operations. Letters or even strings are also comparable: a<b<c<d<...<z

Good job, man!

@grimblefritz
Copy link
Author

Including string comparisons amplifies the complexity of the parser as well as the definition of the logic (ie, user confusion.)

Consider "05>5". Is that a numeric comparison? Is "greater than" based on string length, or sort order?

What about "a>10"? Since one operand is non-numeric does that force a string comparison? Or do strings compared to numbers evaluate as zero?

And "THIS>this"? Does case matter? Is THIS greater than this because it sorts out first in an ASCII collation? What about in other collations? What about symbols? Unicode characters?

There are definite rules for numeric comparisons, but strings are a madhouse. This is why I proposed, in keeping with genders+nodeattr being a simple query system, for non-numeric operands to cause a short-circuit evaluation and return a null result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants