pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
IS as a binary operator
2+ messages / 2 participants
[nested] [flat]

* IS as a binary operator
@ 2023-02-25 10:38  david wheeler <hippysoyboy@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: david wheeler @ 2023-02-25 10:38 UTC (permalink / raw)
  To: pgsql-general

Heya folks, 

Recently I've been using a Kotlin library SQLDelight <https://cashapp.github.io/sqldelight/2.0.0-alpha05/; 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

[1] https://github.com/cashapp/sqldelight/issues/3863

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: IS as a binary operator
@ 2023-02-25 16:54  Tom Lane <tgl@sss.pgh.pa.us>
  parent: david wheeler <hippysoyboy@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-02-25 16:54 UTC (permalink / raw)
  To: david wheeler <hippysoyboy@gmail.com>; +Cc: pgsql-general

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-02-25 16:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-02-25 10:38 IS as a binary operator david wheeler <hippysoyboy@gmail.com>
2023-02-25 16:54 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox