Re: using limit with delete

From: Neil Conway <neilc(at)samurai(dot)com>
To: Chris Smith <chris(at)interspire(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: using limit with delete
Date: 2005-04-07 02:02:24
Message-ID: 425494B0.3020806@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Smith 2005-04-07 02:11:26 Re: using limit with delete
Previous Message Chris Smith 2005-04-07 01:51:10 using limit with delete