You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
SqlException "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." returned when using a composed query when the subquery has a groupBy clause. This is because SQLProvider includes the groupBy key in the select clause even if you haven't asked for it.
To Reproduce
Steps to reproduce the behavior:
Take a query that uses a subquery with a groupBy clause, e.g.:
lettest=letlastAddresses=
query {for a in dbContext.Address do
where (a.Deleted.IsNone)
groupBy a.UserId into g
select (g.Max(fun a -> a.Id))}letresult=
query {for a in dbContext.Address do
where (lastAddresses.Contains(a.Id))
select a
}
result
Run the query, and you get the SqlException described above.
Inspecting the SQL produced, you can see the problem:
SELECT*FROM [address] as [a]
WHERE (([a].[Id] IN (
SELECT [a].[UserId] as'[a].[UserId]', MAX([a].[Id]) as'[a].[MAX_Id]'FROM [address] as [a]
WHERE (([a].[Deleted] IS NOT NULL))
GROUP BY [a].[UserId]))
)
Basically SQLProvider is including [a].[UserId] as '[a].[UserId]' in the select clause of the subquery. The IN clause is only expecting a single column in the subquery so fails.
Expected behavior
SQLProvider should only return the columns requested in the query. The SQL produced should be:
SELECT*FROM [address] as [a]
WHERE (([a].[Id] IN (
SELECTMAX([a].[Id]) as'[a].[MAX_Id]'FROM [address] as [a]
WHERE (([a].[Deleted] IS NOT NULL))
GROUP BY [a].[UserId]))
)
Additional context
If we wanted the groupBy key included in the select statement, we could do so by requesting it explicitly, so there is no reason why SQLProvider should do this for us unsolicitedly:
lettest=letlastAddresses=
query {for a in dbContext.Address do
where (a.Deleted.IsNone)
groupBy a.UserId into g
select (g.Key, g.Max(fun a -> a.Id))}letresult=
query {for a in dbContext.Address do
where (lastAddresses.Contains(a.Id))
select a
}
result
The text was updated successfully, but these errors were encountered:
Describe the bug
SqlException "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." returned when using a composed query when the subquery has a groupBy clause. This is because SQLProvider includes the groupBy key in the select clause even if you haven't asked for it.
To Reproduce
Steps to reproduce the behavior:
[a].[UserId] as '[a].[UserId]'
in the select clause of the subquery. TheIN
clause is only expecting a single column in the subquery so fails.Expected behavior
SQLProvider should only return the columns requested in the query. The SQL produced should be:
Additional context
If we wanted the groupBy key included in the select statement, we could do so by requesting it explicitly, so there is no reason why SQLProvider should do this for us unsolicitedly:
The text was updated successfully, but these errors were encountered: