Skip to content

Query: TypeCompatibility chart for inference #15586

Description

@smitpatel

When we generate SQL like [c].[DoubleColumn] * 5 = 88 the inferred TypeMapping for constants become DoubleTypeMapping. In order to print out constant we cast value to double which throws following exception.
Message: System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'System.Double'.

Given operator upcasting, we don't need to use DoubleTypeMapping to print 5/88, we can just use int (or whatever type it is). But in order for us to do that, we need the logic in inference.

Activity

  1. self-assigned this
    on May 2, 2019
  2. added this to the Backlog milestone on May 3, 2019
  3. removed their assignment
    on Jun 24, 2019
  4. roji commented on Jul 30, 2019

    @roji
    Member

    Note impact on set operations, where we have different store types coming out of the two sides but it's OK since they're implicitly convertible (see #16813 (comment)).

    We may even consider a chart detailing explicit convertibility, to know which store types can be cast to which other types. This would allow us to add SQL casts if necessary.

  5. smitpatel commented on Jul 31, 2019

    @smitpatel
    ContributorAuthor

    Explicit would be bad idea from provider side because if unknown types encountered you wouldn't know. Implicit side much better that you can be certain you don't need cast. In the absence of which it would be always casted.

  6. roji commented on Apr 25, 2022

    @roji
    Member

    Note additional interesting case: Npgsql translates NewArrayExpression, and infers type mappings across all the provided elements. Heterogeneous/incompatible elements cause an exception (the array must be of a single PG type), but we do support heterogeneous elements when they're implicitly convertible to one another (e.g. same base type with different facet, or even varchar(15) and text). This is currently "hacked" here, but a type compatibility chart would make this better.

  7. added theissue type on Jun 15, 2025
  8. roji commented on Dec 11, 2025

    @roji
    Member

    See also #37300 (comment), where comparing a short to an int results in a false literal, although that comparison should translate (with the short implicitly being cast up to int).

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions