Skip to content

[jooq] Add DELETE LIMIT emulation via subquery #217

@krasnovdm

Description

@krasnovdm

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions