Skip to content

Support DELETE with LIMIT and ORDER BY #100

Closed

Description

@MocioF

LIMIT has been fixed for UPDATE with this PR #93 but DELETE LIMIT is still unsupported.

Activity

  1. adamziel commented on Apr 17, 2024

    @adamziel
    Collaborator
  2. changed the title [-]Support DELETE LIMIT[/-] [+]Support `DELETE` with `LIMIT` and `ORDER BY`[/+] on Aug 12, 2025
  3. JanJakes commented on Aug 12, 2025

    @JanJakes
    Member

    The new SQLite driver supports UPDATE with both ORDER BY and LIMIT, but for the DELETE statement it's not implemented yet. I updated the title to mention ORDER BY as well.

  4. MocioF commented on Aug 13, 2025

    @MocioF
    Author

    Hi @JanJakes, it seems to me that the driver translates the MySql query as if the sqlite used is compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT (https://sqlite.org/compile.html#enable_update_delete_limit), but it is not.
    I am not sure if is it possible to add in playground a sqlite version built with this flag but as a workaround, the query DELETE ... LIMIT, could be translated in something as:

    DELETE FROM table
    WHERE someColumn in
    (
      SELECT someColumn FROM table WHERE SomeCondition LIMIT 200
    )
    
  5. JanJakes commented on Aug 14, 2025

    @JanJakes
    Member

    Hi @MocioF, as this issue states, this is not yet implemented for the DELETE statement.

  6. ivan-ottinger commented on Apr 17, 2026

    @ivan-ottinger

    Just a quick note that I run into this issue today while testing one Studio site.

    [17-Apr-2026 11:50:05 UTC] WordPress database error <div style="clear:both">&nbsp;</div>
    <div class="queries" style="clear:both;margin-bottom:2px;border:red dotted thin;">
    <p>MySQL query:</p>
    <p>DELETE FROM wp_actionscheduler_actions WHERE hook = 'wp_mail_smtp_queue_process' AND status = 'complete' LIMIT 10</p>
    <p>Queries made or created this session were:</p>
    <ol>
    <li>Executing: BEGIN IMMEDIATE | (no parameters)</li>
    <li>Executing: DELETE FROM `wp_actionscheduler_actions` WHERE `hook` = &#039;wp_mail_smtp_queue_process&#039; AND `status` = &#039;complete&#039; LIMIT 10 | (no parameters)</li>
    <li>Executing: ROLLBACK | (no parameters)</li>
    </ol>
    </div>
    <div style="clear:both;margin-bottom:2px;border:red dotted thin;" class="error_message" style="border-bottom:dotted blue thin;">
    SQLSTATE[HY000]: General error: 1 near "LIMIT": syntax error
    </div>
    <p>Backtrace:</p>
    <pre>#0 /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/database/sqlite/class-wp-pdo-mysql-on-sqlite.php(921): WP_PDO_MySQL_On_SQLite->new_driver_exception('SQLSTATE[HY000]...', 'HY000', Object(PDOException))
    #1 /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/database/sqlite/class-wp-sqlite-driver.php(160): WP_PDO_MySQL_On_SQLite->query('DELETE FROM wp_...', 5)
    #2 /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(543): WP_SQLite_Driver->query('DELETE FROM wp_...')
    #3 /wordpress/wp-content/mu-plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(455): WP_SQLite_DB->_do_query('DELETE FROM wp_...')
    #4 /wordpress/wp-content/plugins/wp-mail-smtp/src/Tasks/Task.php(389): WP_SQLite_DB->query('DELETE FROM wp_...')
    #5 /wordpress/wp-content/plugins/wp-mail-smtp/src/Tasks/Queue/ProcessQueueTask.php(82): WPMailSMTP\Tasks\Task->remove_completed(10)
    #6 /wordpress/wp-includes/class-wp-hook.php(341): WPMailSMTP\Tasks\Queue\ProcessQueueTask->cleanup('')
    #7 /wordpress/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters('', Array)
    #8 /wordpress/wp-includes/plugin.php(522): WP_Hook->do_action(Array)
    #9 /wordpress/wp-content/plugins/post-expirator/lib/vendor/woocommerce/action-scheduler/classes/ActionScheduler_QueueRunner.php(163): do_action('action_schedule...')
    #10 /wordpress/wp-includes/class-wp-hook.php(341): ActionScheduler_QueueRunner->run('Async Request')
    #11 /wordpress/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters('', Array)
    #12 /wordpress/wp-includes/plugin.php(522): WP_Hook->do_action(Array)
    #13 /wordpress/wp-content/plugins/post-expirator/lib/vendor/woocommerce/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(48): do_action('action_schedule...', 'Async Request')
    #14 /wordpress/wp-content/plugins/post-expirator/lib/vendor/woocommerce/action-scheduler/lib/WP_Async_Request.php(174): ActionScheduler_AsyncRequest_QueueRunner->handle()
    #15 /wordpress/wp-includes/class-wp-hook.php(341): WP_Async_Request->maybe_handle('')
    #16 /wordpress/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters('', Array)
    #17 /wordpress/wp-includes/plugin.php(522): WP_Hook->do_action(Array)
    #18 /wordpress/wp-admin/admin-ajax.php(192): do_action('wp_ajax_as_asyn...')
    #19 {main}</pre>
     for query DELETE FROM wp_actionscheduler_actions WHERE hook = 'wp_mail_smtp_queue_process' AND status = 'complete' LIMIT 10 made by do_action('wp_ajax_as_async_request_queue_runner'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Request->maybe_handle, ActionScheduler_AsyncRequest_QueueRunner->handle, do_action('action_scheduler_run_queue'), WP_Hook->do_action, WP_Hook->apply_filters, ActionScheduler_QueueRunner->run, do_action('action_scheduler_after_process_queue'), WP_Hook->do_action, WP_Hook->apply_filters, WPMailSMTP\Tasks\Queue\ProcessQueueTask->cleanup, WPMailSMTP\Tasks\Task->remove_completed, WP_SQLite_DB->query, WP_SQLite_DB->print_error
    
  7. JanJakes commented on Apr 17, 2026

    @JanJakes
    Member

    Ah, that's an easy fix: #365

  8. ivan-ottinger commented on Apr 21, 2026

    @ivan-ottinger

    Ah, that's an easy fix: #365

    Nice! Thanks for the fix, Jan!

  9. added a commit that references this issue on Apr 22, 2026
    bd461a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions