pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUPDATE & LIMIT together?
4+ messages / 2 participants
[nested] [flat]
* UPDATE & LIMIT together?
@ 2002-08-28 16:09 tp <tp@emaze.net>
0 siblings, 1 reply; 4+ messages in thread
From: tp @ 2002-08-28 16:09 UTC (permalink / raw)
To: pgsql-sql
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;
This is not supported by postgres.
Is there some easy solution that does not require locking?
-tp
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: UPDATE & LIMIT together?
@ 2002-08-28 17:01 Bruce Momjian <pgman@candle.pha.pa.us>
parent: tp <tp@emaze.net>
0 siblings, 1 reply; 4+ messages in thread
From: Bruce Momjian @ 2002-08-28 17:01 UTC (permalink / raw)
To: tp@emaze.net; +Cc: pgsql-sql
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;
>
> This is not supported by postgres.
>
> Is there some easy solution that does not require locking?
>
>
> -tp
-- End of PGP section, PGP failed!
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: UPDATE & LIMIT together?
@ 2002-09-03 08:37 tp <tp@emaze.net>
parent: Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: tp @ 2002-09-03 08:37 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: 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@candle.pha.pa.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;
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: UPDATE & LIMIT together?
@ 2002-09-03 18:39 Bruce Momjian <pgman@candle.pha.pa.us>
parent: tp <tp@emaze.net>
0 siblings, 0 replies; 4+ messages in thread
From: Bruce Momjian @ 2002-09-03 18:39 UTC (permalink / raw)
To: tp@emaze.net; +Cc: pgsql-sql
tp wrote:
> 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)
Without an ORDER BY, I am not sure what that LIMIT is returning.
I don't know of a faster way.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-09-03 18:39 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-08-28 16:09 UPDATE & LIMIT together? tp <tp@emaze.net>
2002-08-28 17:01 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-09-03 08:37 ` tp <tp@emaze.net>
2002-09-03 18:39 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox