delete statement returning too many results

From: Arlo Louis O'Keeffe <gnomelver(at)k5d(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: delete statement returning too many results
Date: 2022-11-28 13:29:30
Message-ID: 34484222-02BB-408A-8FBB-DCE0F64D96B5@k5d.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello everyone,

I am seeing weird behaviour of a delete statement that is returning more results than I am expecting.

This is the query:

DELETE FROM queue
WHERE
id IN (
SELECT id
FROM queue
ORDER BY id
LIMIT 1
FOR UPDATE
SKIP LOCKED
)
RETURNING *;

My understanding is that the limit in the sub-select should prevent this query from ever
returning more than one result. Sadly I am seeing cases where there is more than one result.

This repository has a Java setup that pretty reliably reproduces my issue:
https://github.com/ArloL/postgres-query-error-demo

I checked the docs for select and delete and couldn’t find any hint for cases
where the behaviour of limit might be surprising.

Am I missing something?

Thanks,

Arlo

Responses

Browse pgsql-general by date

  From Date Subject
Next Message j.emerlik 2022-11-28 14:01:10 Standby restore_command
Previous Message Pavel Luzanov 2022-11-28 13:26:49 Re: how to implement add using upsert and trigger?