Re: UPDATE & LIMIT together?

From: tp <tp(at)emaze(dot)net>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: UPDATE & LIMIT together?
Date: 2002-09-03 08:37:27
Message-ID: 20020903083727.GH5674@emaze.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hmm,,

thanks so far, it helped.

The query is horrible slow on full tables (>100.000 rows).
Is there any other solution? I just want to have the 'next 10 entries'
WHERE state=10 and update state=20.
(so that on the next request i or another process only gets the
new entires in queue).

My query now looks like:
UPDATE queue SET state=20 WHERE (id) IN (SELECT id FROM queue LIMIT 10)

-tp

Bruce Momjian(pgman(at)candle(dot)pha(dot)pa(dot)us)@Wed, Aug 28, 2002 at 01:01:36PM -0400:
>
> You have to use a subquery returning the tables primary key to the
> UPDATE:
>
> UPDATE tab SET x=1
> WHERE (primkey, col) IN (
> SELECT primkey,col FROM tab
> ORDER BY col
> LIMIT 10)
>
> ---------------------------------------------------------------------------
>
> tp wrote:
> -- Start of PGP signed section.
> > Hi
> >
> > I want to SELECT at max. 10 rows and SET a variable for the
> > select 10 rows with the same query.
> >
> > Under mysql i can use:
> > UPDATE table SET uniq_iq=12345 LIMIT 10
> > SELECT * FROM table WHERE uniq_id=1234;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hubert depesz Lubaczewski 2002-09-03 08:41:44 Re: RFC822 Checker
Previous Message Stephan Szabo 2002-09-03 04:06:05 Re: union optimization in views