pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jean-Christian Imbeault <jc@mega-bucks.co.jp>
To: PostgreSQL-general <pgsql-general@postgreSQL.org>
Subject: Locking rows
Date: Fri, 28 Feb 2003 19:26:55 +0900
Message-ID: <3E5F396F.4090507@mega-bucks.co.jp> (raw)

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




view thread (19+ messages)  latest in thread

Message-ID: <3E5F396F.4090507@mega-bucks.co.jp>
Permalink:  ../3E5F396F.4090507@mega-bucks.co.jp/
Also on:    postgresql.org/message-id/3E5F396F.4090507@mega-bucks.co.jp

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: jc@mega-bucks.co.jp
  Subject: Re: Locking rows
  In-Reply-To: <3E5F396F.4090507@mega-bucks.co.jp>
  References: <3E5F396F.4090507@mega-bucks.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox