Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upShould `types::Text` be an alias for `types::VarChar`? #287
Comments
sgrif
added
the
discussion desired
label
Apr 20, 2016
This comment has been minimized.
|
Explored this a bit. Tests mostly passed. Only place I had to make a change outside of Diesel's code was here, as I also dug into how this might affect us on the supported backends. SQLite we already know for sure won't be affected, as there is on varchar or text type, only the text affinity. For PG, things are kinda similar. We already know that they're treated the same under the hood. In the public API, it's a similar story. The
This works because there's a cast defined between the two types.
The wrinkle here is that the same is not true for We could maybe work around that by doing some sort of internal nonsense that only affects arrays. While this might be an annoying gotcha, I think it's relatively low cost to just have the situation be "if you're using a text array, use |
sgrif commentedApr 20, 2016
•
edited
Right now these are different types, with separate bindings for all related things. As things stand right now, functions can only take arguments of a single type. For example, you can pass an expression of type
VarChartolower, but not one of typeText. We could certainly implement it in such a way that we use a trait to mark valid argument types, but that would end up with ambiguity when you dolower("STRING LITERAL")since that could be an expression of either type, and I'm not sure that type inference will always be able to save us.All backends seem to treat these as pretty much identical. The only case that I can see where they differ is in things like limits, which we cannot enforce on the Diesel side1. Are there backends which treat them differently, either for valid arguments to functions/operators or for serialization/deserialization? If not, I think we should just make these aliases for one another.
1Ok, we technically could enforce this, and it would be more correct. But this is the same as how technically we shouldn't provide
impl ToSql<VarChar, Pg> for Stringbecause PG doesn't allow nul bytes so we should only allowCStringtechnically. While we do open up one case for runtime errors, the useability trade off is more than worth it for me.