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

Arithmetic on optionals #842

Closed
dbrgn opened this Issue Apr 5, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@dbrgn
Contributor

dbrgn commented Apr 5, 2017

This does not work...

update(posts.filter(id.eq(7)).set(read_count.eq(read_count + 1))

...if read_count is nullable.

According to my tests, Pg, MySQL and SQLite all return null for SELECT NULL + 1.

This page seems to agree: http://www-cs-students.stanford.edu/~wlam/compsci/sqlnulls

An arithmetic operation involving a NULL returns NULL. For example, NULL minus NULL yields NULL, not zero.

I didn't check the SQL ISO standard though.

Note also that aggregation function like SUM() seem to ignore null values.

Maybe addition and other arithmetic operations could be implemented on Nullable<Integer> and others?

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 5, 2017

The ISO standard is that any operation on a null value returns null. I'm fine with adding ops for nullable values (preferably as a single blanket impl if possible)

Eijebong added a commit to Eijebong/diesel that referenced this issue Apr 6, 2017

Allow numeric operations on nullable columns.
For now you can only do operations between two nullable columns as rust
doesn't allow us to implement a trait twice for the same type without
specialization.

Fixes diesel-rs#842

Eijebong added a commit to Eijebong/diesel that referenced this issue Apr 7, 2017

Allow numeric operations on nullable columns.
For now you can only do operations between two nullable columns as rust
doesn't allow us to implement a trait twice for the same type without
specialization.

Fixes diesel-rs#842

@sgrif sgrif closed this in 3e59e91 Apr 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment