Re: using limit with delete - Mailing list pgsql-general

From Neil Conway
Subject Re: using limit with delete
Date
Msg-id 425494B0.3020806@samurai.com
Whole thread Raw
In response to using limit with delete  (Chris Smith <chris@interspire.com>)
Responses Re: using limit with delete  (Chris Smith <chris@interspire.com>)
Re: using limit with delete  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Re: using limit with delete  (Chris Smith <chris@interspire.com>)
List pgsql-general
Chris Smith wrote:
> I'm trying to use a limit clause with delete, but it doesn't work at the
> moment

It isn't in the SQL standard, and it would have undefined behavior: the
sort order of a result set without ORDER BY is unspecified, so you would
have no way to predict which rows DELETE would remove.

> delete from table where x='1' limit 1000;

You could use a subquery to achieve this:

DELETE FROM table WHERE x IN
     (SELECT x FROM table ... ORDER BY ... LIMIT ...);

-Neil

pgsql-general by date:

Previous
From: Chris Smith
Date:
Subject: using limit with delete
Next
From: Chris Smith
Date:
Subject: Re: using limit with delete