Problem
When using jOOQ's delete(...).limit(n) with the YDB dialect, the generated SQL is:
DELETE FROM `test` LIMIT $jp1
YQL does not support the LIMIT clause on DELETE statements, so this fails with:
Status{code = GENERIC_ERROR(code=400080), issues = [19:3 - 19:3: extraneous input 'limit' expecting {<EOF>, ';'} (S_ERROR)]}
Reproducer
dsl.delete(TEST).limit(10).execute();
// → DELETE FROM `test` LIMIT $jp1 (GENERIC_ERROR)
Expected behavior
The dialect should emulate DELETE LIMIT n by rewriting it as a subquery using the table's primary key:
DELETE FROM `test` WHERE `key` IN (SELECT `key` FROM `test` LIMIT $jp1)
For composite PKs:
DELETE FROM `episodes`
WHERE (`series_id`, `season_id`, `episode_id`) IN (
SELECT `series_id`, `season_id`, `episode_id`
FROM `episodes`
LIMIT $jp1
)
Implementation notes
jOOQ already has a similar emulation tracked in jOOQ/jOOQ#7839 for other databases that lack native DELETE LIMIT support.
For this dialect the natural place is a custom DeleteQuery implementation in org.jooq.impl (mirroring the existing UpsertReplaceQueryImpl pattern), wired in via YdbDSLContextImpl.deleteQuery(). The PK fields are available through table.getPrimaryKey().getFields() when the table is code-generated. When PK is unavailable the implementation should throw a descriptive error.
Environment
jooq-ydb-dialect version: 1.2.1
- jOOQ: 3.19.x
- YQL does not support
DELETE ... LIMIT (confirmed)
Problem
When using jOOQ's
delete(...).limit(n)with the YDB dialect, the generated SQL is:YQL does not support the
LIMITclause onDELETEstatements, so this fails with:Reproducer
Expected behavior
The dialect should emulate
DELETE LIMIT nby rewriting it as a subquery using the table's primary key:For composite PKs:
Implementation notes
jOOQ already has a similar emulation tracked in jOOQ/jOOQ#7839 for other databases that lack native
DELETE LIMITsupport.For this dialect the natural place is a custom
DeleteQueryimplementation inorg.jooq.impl(mirroring the existingUpsertReplaceQueryImplpattern), wired in viaYdbDSLContextImpl.deleteQuery(). The PK fields are available throughtable.getPrimaryKey().getFields()when the table is code-generated. When PK is unavailable the implementation should throw a descriptive error.Environment
jooq-ydb-dialectversion: 1.2.1DELETE ... LIMIT(confirmed)