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

Add IS DISTINCT FROM and IS NOT DISTINCT FROM operators for Postgres #673

Closed
icopp opened this issue Sep 1, 2023 · 4 comments
Closed

Add IS DISTINCT FROM and IS NOT DISTINCT FROM operators for Postgres #673

icopp opened this issue Sep 1, 2023 · 4 comments
Labels
api Related to library's API enhancement New feature or request postgres Related to PostgreSQL

Comments

@icopp
Copy link

icopp commented Sep 1, 2023

These are functionally identical to <> and = respectively, except that they treat NULL as a known value (e.g. NULL IS DISTINCT FROM 'value' returns TRUE, NULL IS NOT DISTINCT FROM 'value' returns FALSE).

@koskimas
Copy link
Member

koskimas commented Sep 1, 2023

How's that different from NULL IS NOT 'value' and NULL IS 'value' that are already supported?

You can already use any operator like this:

where('foo', sql`is distinct from`, bar) 

@igalklebanov igalklebanov added enhancement New feature or request postgres Related to PostgreSQL api Related to library's API labels Sep 1, 2023
@icopp
Copy link
Author

icopp commented Sep 1, 2023

How's that different from NULL IS NOT 'value' and NULL IS 'value' that are already supported?

Like this:

SELECT NULL IS DISTINCT FROM NULL; -- false
SELECT NULL IS NOT DISTINCT FROM NULL; -- true

SELECT 'value' IS DISTINCT FROM NULL; -- true
SELECT 'value' IS NOT DISTINCT FROM NULL; -- false

SELECT 'value' IS DISTINCT FROM 'value'; -- true
SELECT 'value' IS NOT DISTINCT FROM 'value'; -- false

The key difference is that it handles NULL and non-NULL values in a single statement, without needing to do things like a = b OR (a IS NULL AND B IS NULL) OR (a IS NOT NULL AND B IS NOT NULL).

You can already use any operator like this:

where('foo', sql`is distinct from`, bar) 

This was what I initially tried, but the TypeScript inference here breaks badly in some situations, like if you have a .where() on a .doUpdateSet().

@koskimas
Copy link
Member

koskimas commented Sep 1, 2023

Breaks how?

@koskimas
Copy link
Member

koskimas commented Sep 2, 2023

@icopp What do you mean by

This was what I initially tried, but the TypeScript inference here breaks badly in some situations, like if you have a .where() on a .doUpdateSet().

Could you provide the code you're running and the error you get.

@kysely-org kysely-org locked as resolved and limited conversation to collaborators Sep 3, 2023
Gaspero pushed a commit to Gaspero/kysely that referenced this issue Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api Related to library's API enhancement New feature or request postgres Related to PostgreSQL
Projects
None yet
Development

No branches or pull requests

3 participants