Locking rows

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: PostgreSQL-general <pgsql-general(at)postgreSQL(dot)org>
Subject: Locking rows
Date: 2003-02-28 10:26:55
Message-ID: 3E5F396F.4090507@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have written an application that prints out data from a database. One
problem I am encountering is in the time it takes to generate the print
file the data may have changed.

I was thinking that a way around this would be to lock the rows that are
used to generate the print file. However I am not quite sure how to best
go about this.

Is locking the rows the best (or simplest) solution?

If locking is a good idea how could I lock and then unlock the rows
returned by this (somewhat ugly) query?

select prod_id, sum(quantity), case when (select stock_qty+cancelled_qty
from stock where pid=prod_id) is null then 0 else (select
stock_qty+cancelled_qty from stock where pid=prod_id) end as stock_qty
from invoice_li, invoices where invoices.id=invoice_id AND dist_id=1 AND
NOT invoices.cancelled AND NOT invoice_li.cancelled group by prod_id;

I will also be doing some other select queries between this one and the
printing (I need to get more information on each prod_id returned).

I've read the iDocs and Bruce's online manual but can seem to find any
info on the syntax for locking other that for SELECT FOR UPDATE. And
even then the docs don't state how to remove the lock created by a
SELECT FOR UPDATE.

Thanks!

Jc

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan Gravgaard 2003-02-28 10:28:30 Warning: Supplied argument is not a valid PostgreSQL link resource
Previous Message Tom Gilbert 2003-02-28 10:22:21 Re: initdb hangs even though ipc-daemon is running?