From: | Karel Zak <zakkr(at)zf(dot)jcu(dot)cz> |
---|---|
To: | Jie Liang <jliang(at)ipinc(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: select ... for update |
Date: | 2000-12-13 08:28:29 |
Message-ID: | Pine.LNX.3.96.1001213090602.2387B-100000@ara.zf.jcu.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> > Hi,
>
> How can I use select ... for update to update limit to update what I
> select??
First thing - the SELECT FOR UPDATE is not merge of SELECT and UPDATE
but transaction option. The PostgreSQL use row-locking for UPDATEed rows.
Standard SELECT ignore this lock, but SELECT FOR UPDATE wait until
*other* transaction with UPDATE will commited.
> somewhat like:
> select url,id from mytable for update order by priority,id limit 5;
^^^^^^^^^^^^^^^^^^^
see the SELECT's syntax, ORDER BY must be before FOR UPDATE.
> I want update the id in above return like:
> update mytable set allocatedto='whatever' where id in above return set.
Can't you in UPDATE's WHERE define some 'id' as in above SELECT?
An example (via subselect):
UPDATE mytable SET allocatedto='whatever'
WHERE id IN (
SELECT id FROM mytable ORDER BY priority,id LIMIT 5
);
But it not will too much fast... better is define relevant 'id'
inside UPDATE's WHERE without sub-select, but if you need define it via
ORDER+LIMIT it's impossible.
Karel
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Boettcher | 2000-12-13 09:55:03 | Postgres closing the connection too fast with php4+apache |
Previous Message | Luca Pregliasco | 2000-12-12 23:50:40 | Re: Persistent Connects (pg_pconnect) |