PostgresSQL. Delete with Take (linq2db v3.1.0)
See original GitHub issueUsing Delete/DeleteAsync methods with Take generates sql which doesnt work.
Exception message:
Stack trace:
18:38:34|Error|ServersWorker|42601: ошибка синтаксиса (примерное положение: "LIMIT") Npgsql.PostgresException (0x80004005): 42601: ошибка синтаксиса (примерное положение: "LIMIT")
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.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
at LinqToDB.Data.DataConnection.ExecuteNonQueryAsync(CancellationToken cancellationToken)
at LinqToDB.Data.DataConnection.QueryRunner.ExecuteNonQueryAsync(CancellationToken cancellationToken)
at LinqToDB.Linq.QueryRunner.NonQueryQueryAsync(Query query, IDataContext dataContext, Expression expression, Object[] ps, Object[] preambles, CancellationToken cancellationToken)
at LinqToDB.Linq.ExpressionQuery`1.LinqToDB.Async.IQueryProviderAsync.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at LinqToDB.LinqExtensions.DeleteAsync[T](IQueryable`1 source, CancellationToken token)
at Services.Services.Servers.ServerDeletion.DeleteMt5Deals(Int32 serverId) in C:\Services\Servers\ServerDeletion.cs:line 97
at Services.Services.Servers.ServerDeletion.DeleteMt5(Server mt5Server) in C:\Services\Servers\ServerDeletion.cs:line 36
at Services.Services.Servers.ServerDeletion.DeleteServer(Server server) in C:\Services\Servers\ServerDeletion.cs:line 29
at Core.Workers.ServersWorker.ExecuteAsync(CancellationToken stoppingToken) in C:\Services\Servers\ServerDeletion.cs:line 41
Exception data:
Severity: ОШИБКА
SqlState: 42601
MessageText: ошибка синтаксиса (примерное положение: "LIMIT")
Position: 63
File: scan.l
Line: 1149
Routine: scanner_yyerror
Steps to reproduce
This query causes error above:
deleted = await _context.Deals
.Where(w => w.ServerId == serverId)
.Take(_chunkSize)
.DeleteAsync();
Generated SQL:
DECLARE @serverId Integer -- Int32
SET @serverId = 1
DECLARE @take Integer -- Int32
SET @take = 10000
DELETE FROM
"public".deals w
WHERE
w.server_id = :serverId
LIMIT :take
Without Take() it works fine.
Environment details
linq2db installed packages:
<PackageReference Include="linq2db" Version="3.1.0" />
<PackageReference Include="linq2db.AspNet" Version="3.1.0" />
<PackageReference Include="linq2db.t4models" Version="3.1.0" />
Database Provider: PostgreSQL 12 Operating system: Win10 .NET Framework: netcoreapp3.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Documentation: 15: DELETE
DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is absent, the effect is to delete...
Read more >linq2db 5.0.0-preview.1
LINQ to DB is a data access technology that provides a run-time infrastructure for managing relational data as objects.
Read more >How to delete multiple rows using LINQ in linq2db ...
You can use the following solution to delete multiple rows using LINQ in linq2db Templates based on two tables: ( from p in...
Read more >PostgreSQL Delete Data in a Table
In PostgreSQL, use the DELETE statement to delete one or more rows in the table. It only deletes the data from the table...
Read more >How to: Delete Rows From the Database - ADO.NET ...
You can delete rows in a database by removing the corresponding LINQ to SQL objects from their table-related collection. LINQ to SQL ......
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
you should be able to delete it using filter by top 10 ids (if you have unique single-column id in this table)
After two years, still not fixed? I thought it’s an easy fix. YEs, I can write delete(x=>idquery.take(100).contains(x.id)), but it’s much more elegant to write query.take(100).delete(). besides it worked on SQL server. 😃 Any plan to update the postgresql driver? I found a lot linqtodb syntax does not work on postgresql. Upinsert won’t work either. Seems postgresql for linqtodb is not quite ready?
Calvin