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

CAST operator missing in generated SQL #2862

Closed
FelixLorenz opened this issue Dec 14, 2023 · 5 comments
Closed

CAST operator missing in generated SQL #2862

FelixLorenz opened this issue Dec 14, 2023 · 5 comments
Assignees
Milestone

Comments

@FelixLorenz
Copy link
Contributor

Say there are two classes

public class Inner
{
  public int Integer1 {get; }
  public int Integer2 {get; }
}

public class MyEntity
{
  public Inner Inner {get; }
}

and Entity is stored as a document by marten.
When then querying like:

session.Query<MyEntity>()
  .Where(e => e.Inner.Integer1 == n)
  .OrderByDescending(e => e.Inner.Integer2)
  .FirstOrDefault()

following sql gets produced:

select d.id, d.data, d.mt_version from public.mt_doc_myentity as d where CAST(d.data -> 'Inner' ->> 'Integer1 ' as integer) = :p0 order by d.data -> 'Inner' ->> 'Integer2 ' desc;

which leads to alphanumeric ordering. Expected was numeric ordering.
I assume that marten misses to add the CAST operator such that the following sql was produced:

select d.id, d.data, d.mt_version from public.mt_doc_myentity as d where CAST(d.data -> 'Inner' ->> 'Integer1 ' as integer) = :p0 order by CAST(d.data -> 'Inner' ->> 'Integer2' as integer) desc;


Also discussed here on the marten discord

@jeremydmiller jeremydmiller added this to the 7.0.0 milestone Dec 15, 2023
@jeremydmiller jeremydmiller self-assigned this Dec 15, 2023
@jeremydmiller
Copy link
Member

@FelixLorenz What version of Marten are you using? This is fixed in master at least.

@FelixLorenz
Copy link
Contributor Author

@jeremydmiller 7.0.0-beta.2 🤔

@jeremydmiller
Copy link
Member

Nevermind, I was able to repro it on the second attempt. Only the descending sort order

@jeremydmiller
Copy link
Member

Fix coming.

@FelixLorenz
Copy link
Contributor Author

Thanks!

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

No branches or pull requests

2 participants