Re: UPDATE & LIMIT together? - Mailing list pgsql-sql

From Bruce Momjian
Subject Re: UPDATE & LIMIT together?
Date
Msg-id 200208281701.g7SH1aI20777@candle.pha.pa.us
Whole thread Raw
In response to UPDATE & LIMIT together?  (tp <tp@emaze.net>)
Responses Case Statement  ("Tom Haddon" <tom@betterhealthfoundation.org>)
Re: UPDATE & LIMIT together?  (tp <tp@emaze.net>)
List pgsql-sql
You have to use a subquery returning the tables primary key to the
UPDATE:
UPDATE tab SET x=1WHERE (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,
Pennsylvania19073
 


pgsql-sql by date:

Previous
From: friedrich nietzsche
Date:
Subject: nextval...
Next
From: "Tom Haddon"
Date:
Subject: Case Statement