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

($.some_non_existent_key != 'anything') evaluates to false #668

Open
iiian opened this issue Jan 26, 2024 · 3 comments
Open

($.some_non_existent_key != 'anything') evaluates to false #668

iiian opened this issue Jan 26, 2024 · 3 comments

Comments

@iiian
Copy link

iiian commented Jan 26, 2024

input:

{}

expression:

$.some_non_existent_key != 'anything'

evaluates to

false

:(

@iiian
Copy link
Author

iiian commented Jan 26, 2024

I can fix it with

($.some_non_existent_key ? $.some_non_existent_key : null) != 'anything'

Is there a reason why it should be this way from a language design perspective? My initial intuition is that there might be some kind of ambiguity, but if that's true I'd love to know understand what the ambiguity is.

Thanks

@jhorbulyk
Copy link
Contributor

The underlying concept is that undefined behaves like null in SQL and thus

  • undefined = 'something' => false
  • undefined != 'something' => false
  • undefined = undefined => false
  • undefined != undefined => false

Which is probably a concept that needs to be added to https://docs.jsonata.org/comparison-operators

@iiian
Copy link
Author

iiian commented Jan 28, 2024

Hey @jhorbulyk, thanks for the background, I appreciate it.

undefined != 'something' => false

If you don't mind my challenging a bit (respectfully, of course), what is the use case for this? I don't know a whole lot about SQL 3VL, but the idea that (undefined = 'something') and undefined != 'something' both evaluate to false seems like a logical inconsistency even for a 3VL system, and ultimately something that an end-user has to step around. Would it not be more SQL-esque to have undefined = 'something' evaluate to undefined?

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

2 participants