Skip to content
New issue

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

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

Already on GitHub? # to your account

IS DISTINCT FROM operator support #566

Closed
christophe-riolo opened this issue Jan 29, 2025 · 3 comments
Closed

IS DISTINCT FROM operator support #566

christophe-riolo opened this issue Jan 29, 2025 · 3 comments
Assignees

Comments

@christophe-riolo
Copy link

christophe-riolo commented Jan 29, 2025

Hello,

First I need to say that I am very happy with HoneySQL so far, the move to it from Yesql has brought so much flexibility 🙏

I am facing an issue that I am trying to get a POSTGRESQL expression in the form foo IS DISTINCT FROM 'bar' (the latter text being in a variable)
It seems that the operator doesn't exist yet so we have

> (sql/format [ :is-distinct-from :foo bar])
["IS DISTINCT FROM(foo, ?)" "bar"]

which is incorrect

I turned to :inline as I read:

Accepts one or more arguments and tries to render them as a SQL values directly in the formatted SQL string rather than turning it into a positional parameter
keywords and symbols become upper case entities (with - replaced by space)
but then I get:

> (sql/format [:inline :foo :is-distinct-from :bar])
["foo is_distinct_from bar"]

which is still not correct and seems to break the promise of :inline, unless I didn't unserstand how to use it properly which is very possible

So now I have to turn to :raw which is not optimal in terms of inserting my variable in the expression. Did I miss something, either on the use of :inline, or to turn the function into an infix operator ?

Version information
com.github.seancorfield/honeysql {:mvn/version "2.6.1196"}

@p-himik
Copy link
Contributor

p-himik commented Jan 29, 2025

Enabling support from your own code is as simple as executing (sql/register-op! :is-distinct-from).

@christophe-riolo
Copy link
Author

Perfect, exactly what I had missed from the documentation, thank you 🙏

@seancorfield
Copy link
Owner

I'll add :is-distinct-from and :is-not-distinct-from as built-in operators (but, for now, you have a workaround).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants