Incorrectly generated SQL containing LEFT JOIN LATERAL
See original GitHub issueAssume I have a table Matches
with the primary key MatchId
.
The query
from _ in dbContext.Matches.AsQueryable()
select new { X = (from __ in dbContext.Matches.AsQueryable() select 1).ToList() };
generates
SELECT m."MatchId", 1, m0."MatchId"
FROM "Matches" AS m
LEFT JOIN LATERAL "Matches" AS m0 ON TRUE
ORDER BY m."MatchId", m0."MatchId"
which appears to be invalid:
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "AS"
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
Exception data:
Severity: ERROR
SqlState: 42601
MessageText: syntax error at or near "AS"
Position: 87
File: scan.l
Line: 1149
Routine: scanner_yyerror
Provider: Npgsql.EntityFrameworkCore 3.1.4. Database: PostgreSQL 12.2, compiled by Visual C++ build 1914, 64-bit
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
LEFT OUTER JOIN (gives extra rows) problem
I have two tables which I want to join together using a left outer join. However, even though my left table contains only...
Read more >Best practice between using LEFT JOIN or NOT EXISTS
I am using queries within Access against a SQL Server database. sql-server · join · exists · Share.
Read more >13.2.15.9 Lateral Derived Tables
A lateral derived table can occur only in a FROM clause, either in a list of tables separated with commas or in a...
Read more >Slow left join lateral in subquery - postgresql
Based on what the analyze is saying, I believe the issue to be the subquery and the lateral join. Would anyone help me...
Read more >[SQL] LATERAL JOIN - 1001 Ways Of Learning Anything
SELECT m.name FROM manufacturers m LEFT JOIN LATERAL get_product_names(m.id) pname ON true WHERE pname IS NULL; ON TRUE is for the join ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@roji
I came across this issue while debugging a different query. I thought I would report it just in case.
Sadly, I cannot, as I use
System.Linq.Async
OUTER APPLY
will return a single row with null for right when right is empty. Not the case forCROSS JOIN