X-Original-To: pgsql-general@postgreSQL.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3468A47626D for ; Fri, 28 Feb 2003 08:29:31 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 40416-08 for ; Fri, 28 Feb 2003 08:29:19 -0500 (EST) Received: from ns.mega-bucks.co.jp (ns.mega-bucks.co.jp [219.118.175.241]) by postgresql.org (Postfix) with ESMTP id 48995476272 for ; Fri, 28 Feb 2003 05:30:47 -0500 (EST) Received: from mega-bucks.co.jp (dhcp4.mega-bucks.co.jp [192.168.255.103]) by ns.mega-bucks.co.jp (8.12.6/8.12.5) with ESMTP id h1SAUm7o032171 for ; Fri, 28 Feb 2003 19:30:48 +0900 Message-ID: <3E5F396F.4090507@mega-bucks.co.jp> Date: Fri, 28 Feb 2003 19:26:55 +0900 From: Jean-Christian Imbeault User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en, ja MIME-Version: 1.0 To: PostgreSQL-general Subject: Locking rows Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/1695 X-Sequence-Number: 38449 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