Re: using limit with delete

From: Chris Smith <chris(at)interspire(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: using limit with delete
Date: 2005-04-07 02:27:07
Message-ID: 42549A7B.4090801@interspire.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

For the archives...

Using 7.4 so IN() is a little slower, so I rewrote it slightly to be

DELETE FROM table WHERE EXISTS (select x from table .... LIMIT ...);

Works very nicely :)

Thanks again.

Neil Conway wrote:
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>

--
Regards,

Chris Smith

Unit 2, 3 National Street, Rozelle, NSW 2039 Australia

Ph: +61 2 9555 5570
Fx: +61 2 9555 5571

email: info(at)interspire(dot)com
web: http://www.interspire.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Csaba Nagy 2005-04-07 08:21:30 Re: using limit with delete
Previous Message Alvaro Herrera 2005-04-07 02:20:07 Re: using limit with delete