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

From Csaba Nagy
Subject Re: using limit with delete
Date
Msg-id 1112862090.2869.48.camel@coppola.muc.ecircle.de
Whole thread Raw
In response to Re: using limit with delete  (Chris Smith <chris@interspire.com>)
Responses Re: using limit with delete  (Chris Smith <chris@interspire.com>)
List pgsql-general
Hi Chris,

Just a thought: if you have to clear the table anyway, wouldn't it work
for you to use truncate ? That should be faster than delete.

HTH,
Csaba.

On Thu, 2005-04-07 at 04:11, Chris Smith wrote:
> I don't care about the order in my particular case, just that I have to
> clear the table.
>
> I'll try the subquery and see how I go :)
>
> Thanks!
>
> 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@postgresql.org)
> >


pgsql-general by date:

Previous
From: Chris Smith
Date:
Subject: Re: using limit with delete
Next
From: David Gagnon
Date:
Subject: Improvement for COPY command .. unless it already exists (If yes please tell me!)