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

Implement diesel Expression for more types #80

Closed
lephyrius opened this issue Jan 8, 2016 · 3 comments
Closed

Implement diesel Expression for more types #80

lephyrius opened this issue Jan 8, 2016 · 3 comments

Comments

@lephyrius
Copy link

error: the trait `diesel::expression::Expression` is not implemented for the type `u64` 

I got this error.
I solved it with this:

let game = games.filter(id.eq(params.find("id").unwrap().as_u64().unwrap() as i32 )).first(&connection);

This is a bit ugly. Could there be more types supported than just i32?
Any other suggestion than moving this cast to a function?

@sgrif
Copy link
Member

sgrif commented Jan 8, 2016

All integer types are supported for use where appropriate. Unfortunately, the error messages can sometimes be unhelpful due to rust-lang/rust#28894. The trait that it's failing to find is probably AsExpression<types::Integer>. What's allowed here is based on the type of id. It seems likely that your column is of type Integer or Serial, which are both 32 bit signed integers. You can't write 32bit_column.eq(1i64). For BigInteger, you can use 64 bit integers as well. However keep in mind that this type is also signed, and you can only use i64 not u64. PostgreSQL does not have an unsigned integer type.

If my assumptions about your app are incorrect, let me know and I'll re-open.

@sgrif sgrif closed this as completed Jan 8, 2016
@JohnMH
Copy link

JohnMH commented Mar 10, 2018

Why is there no "sql type" for unsigned integers? In MySQL, for example, it is perfectly valid to have an INT UNSIGNED.

@weiznich
Copy link
Member

@JohnMH See #1561 for unsigned integers in MySQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants