Thread: IS as a binary operator
Heya folks,
Recently I've been using a Kotlin library SQLDelight which is great but has some issues with PostgreSQL support. In particular, for null parameters it converts `=` to `IS` - and it treats `IS` as a binary operator (rather than `IS NULL` unary operator), which Postgres doesn't like wrt prepared statements
prepare test(text) as (SELECT * FROM test WHERE nullable_col IS $1); ERROR: syntax error at or near "$1" LINE 1: ...epare test(text) as (SELECT * FROM test WHERE nullable_col IS $1);full details at [1]
I’ve been working on a PR to use `IS NOT DISTINCT FROM` as the `=` substitution for nullable parameters rather than `IS`, however unfortunately that’s not universally supported either (MySQL).
Just wondering if anyone has other ideas? I guess there’s no interest in adding support for `IS` as basically an alias for `IS NOT DISTINCT FROM`? (and `IS NOT` for `IS DISTINCT FROM`)
TIA
David Wheeler
david wheeler <hippysoyboy@gmail.com> writes: > I guess there’s no interest in adding support for `IS` as basically an alias for `IS NOT DISTINCT FROM`? (and `IS NOT`for `IS DISTINCT FROM`) Seems like it'd be impossibly ambiguous with the various sorts of "x IS FOO" constructs that SQL keeps adding. We'd have to make all the FOO keywords fully reserved, which would break people's queries for sure. (Things like CONTENT, DOCUMENT, NORMALIZED, and NFC are unreserved at the moment; and at least the first two of those are pretty plausible as user column names.) Another problem is that currently IS is a type_func_name_keyword, which makes things like this syntactically valid: regression=# select is(42); ERROR: function is(integer) does not exist I doubt we could preserve that in the face of what you suggest. Maybe no one would care, but ... On the whole, I'm afraid of what sorts of "IS" constructs might come out of the committee in future, and what sort of hard place we might find ourselves in if we allow "IS" to not be followed by one of a small set of known keyword sequences. It is a shame that there's nothing less verbose than "IS NOT DISTINCT FROM" for what is surely a pretty common requirement. But we probably need to get the SQL committee on board with any replacement syntax for that. regards, tom lane