-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
Marten 7 Command Failure: 42P08: could not determine data type of parameter $1 #3045
Comments
Reproduced on latest 7.2.0 // we can't pass the input as named parameters until the https://github.com/JasperFx/marten/issues/3045 is fixed. until then we have to duplicate the params
var input = new
{
serviceId = string.IsNullOrEmpty(findRequestsDto.ServiceId) ? null : findRequestsDto.ServiceId,
};
var results = await session.QueryAsync<SomeDto>(
"""
select to_json(t)
from (select r.data ->> 'Status' Status, count(distinct(r.data ->> 'Id')) Count
from mt_doc_someprojection r
where 1 = 1
and (? is null or r.data ->> 'ServiceId' = ?)
group by r.data ->> 'Status') t
""", cancellationToken,
input.serviceId!, input.serviceId!
);
return results; |
@murlakatam I think at most this one is going to be a documentation issue or an assertion to not use nulls for the named arguments like that, because there's no way for Npgsql or Marten to know what DbType to use for that parameter |
Meh, it's going to take digging into Weasel and that just doesn't sound fun on a Friday. Next week. |
Found a more elegant workaround, using params array and ? placeholder, that doesn't require duplication. var results = await session.QueryAsync<SomeDto>(
"""
with config as (select ? service_id)
select to_json(t)
from (select r.data ->> 'Status' Status, count(distinct (r.data ->> 'Id')) Count
from config c
cross join mt_doc_someprojection r
where 1 = 1
and (c.service_id is null or r.data ->> 'ServiceId' = c.service_id)
group by r.data ->> 'Status') t
""", cancellationToken,
input.serviceId! // nullable parameter
); |
@murlakatam I'm feeling dumb here, what's different? |
@jeremydmiller do you mean what's different between two workarounds?
|
Executing raw sql
on IQuerySession
fails in Marten7
, but works fine in Marten6
if you remove
:serviceId is null or
bit the query is running fine.The text was updated successfully, but these errors were encountered: