Thread: Fetch for Update

Fetch for Update

From
"Bob Pawley"
Date:
I haven't been able to find much information on Fetch for Update. Does 8.3
support this command??

If so, could someone please point out my error in the following?

Bob


BEGIN
   SELECT count (p_id.pid.process_id) INTO Proccount
   FROM p_id.p_id
   WHERE process_id = new.process_id;

 Declare
 procgraphic cursor for
 select process_id
 from p_id.p_id
 where p_id.p_id.p_id_id = proc_count.p_id_id;

 Begin

 Fetch first  in procgraphic for update
 Update p_id.p_id
 set proc_graphic_position = one
 From graphics.proc_position
 where graphics.proc_position.proc_count = proccount;


Re: Fetch for Update

From
justin
Date:

Bob Pawley wrote:
> I haven't been able to find much information on Fetch for Update. Does
> 8.3 support this command??
>
> If so, could someone please point out my error in the following?
>
> Bob
>
>
> BEGIN
>   SELECT count (p_id.pid.process_id) INTO Proccount
>   FROM p_id.p_id
>   WHERE process_id = new.process_id;
>
> Declare
> procgraphic cursor for
> select process_id
> from p_id.p_id
> where p_id.p_id.p_id_id = proc_count.p_id_id;
>
> Begin
>
> Fetch first  in procgraphic for update
> Update p_id.p_id
> set proc_graphic_position = one
> From graphics.proc_position
> where graphics.proc_position.proc_count = proccount;
>
>

Theres the Select for update
http://www.postgresql.org/docs/8.1/static/sql-select.html#SQL-FOR-UPDATE-SHARE

which locks the records for the transaction

Re: Fetch for Update

From
Christophe
Date:
On Jul 28, 2008, at 9:16 AM, Bob Pawley wrote:

> I haven't been able to find much information on Fetch for Update.
> Does 8.3 support this command??

Postgres doesn't have an explicit FETCH FOR UDPATE.  You can either
create the cursor with SELECT FOR UPDATE, or UPDATE the row in the
cursor using UPDATE ... CURRENT OF.