-
Notifications
You must be signed in to change notification settings - Fork 223
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
Subquery uses ungrouped column from outer query #2236
Comments
Please reopen this in the EF Core repo - it doesn't seem related to Npgsql. |
With SQL Server provider work properly, but PostgreSQL not support ungrouped column from outer query. EF Core convert subquery to joins, if avoid this convert, can write query same this: from s in (from i in Invoices
group i by i.History.Month into g
select new
{
Month = g.Key,
Total = g.Sum(p => p.Amount)
})
select new
{
s.Month,
s.Total,
Payment = Payments.Where(p => p.History.Month == s.Month).Sum(p => p.Amount)
} sql: SELECT date_part('month', i.history)::INT AS "Month", COALESCE(SUM(i.amount), 0.0) AS "Total", (
SELECT COALESCE(SUM(p.amount), 0.0)
FROM payments AS p
WHERE date_part('month', p.history)::INT = date_part('month', i.history)::INT) AS "Payment"
FROM invoices AS i
GROUP BY date_part('month', i.history)::INT if want open issue in EF Core repo must open with new title. |
Thanks @mojtabakaviani, I can see this happening as you said - note that the query works fine on SQL Server, SQLite and MariaDB. I've opened dotnet/efcore#27266 to discuss this with the EF team, we'll see what can be done about it. |
@mojtabakaviani closing as this is planned to be fixed on the EF Core side for 7.0 - thanks again for flagging this! |
Duplicate of dotnet/efcore#27266 |
Some scenarios need group by with complex key or calc with functions PostgreSQL not support ungrouped column from outer query and must use subquery:
generated sql:
correct sql:
error: subquery uses ungrouped column "i.history" from outer query
EF Core version:
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 6.0.0
Target framework: .NET 6.0
Operating system: Windows 11
IDE: VSCode
The text was updated successfully, but these errors were encountered: