-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
sql: Relax conversion rules in non-lossy cases for greater PG compatibility #37311
Comments
Interestingly, Postgres doesn't permit a variation on this idea:
This example would be permitted if we were to simply permit quote-less numeric constants to be coerced to string. This feels okay to me, but it's worth considering why Postgres (and it's generally permissive type system) doesn't permit this case. |
@andy-kimball, the case you mentioned would actually type-check just fine given this proposal: the Implementing a subset of this proposal is a possibility (maybe only in VALUES clauses or something?) but it seems kind of hard. I have a simple patch that permits numeric constants to become strings, but it does it everywhere, which leads to these issues. #38204 |
@rohany maybe you would be interested in trying this out, given your recent adventures with the typechecker? This is directly related the "constant upcast" phase I was telling you about. |
Work for cockroachdb#37311. Integer to string is not a lossy conversion, and could be performed implicitly, but only for literals. This makes things like inserting int valued constants into a column of strings, which is something some ORMS do. Open to comments about this. Release justification: Will be updated later. Release note: None
We have marked this issue as stale because it has been inactive for |
Any news here? Is there anything we can do to help with resolving this issue? |
The first example in this issue will succeed in the next major release, v22.1, now that assignment casts have been implemented. The example given by @jordanlewis above is not yet supported because it is an implicit cast. See the implicit cast meta-issue #75101, and the issue specific to CASE expressions #75103. I'll close this issue. |
Suggestion
In cases where a conversion is non-lossy and non-ambiguous, we should consider doing an implicit conversion. For example:
Converting from
Int
toString
is not lossy, and in the context the conversion is not ambiguous (i.e. it's not a case likeSELECT '01' = 1
). Doing this will give CRDB greater compatibility with PG without compromising type safety.Use case
When using the off-the-shelf
ActiveRecord
Postgres driver, I saw the following error when invokingrake db:reset
:It turns out the reason is because
ActiveRecord
generates the following SQL, even thoughversion
is avarchar
column:The text was updated successfully, but these errors were encountered: