Re: Is there a way to query whether a table has been changed or not?

From: Jan Ploski <jpljpl(at)gmx(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is there a way to query whether a table has been changed or not?
Date: 2002-09-09 15:04:26
Message-ID: 13799530.1031583866748.JavaMail.jpl@remotejava
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 06, 2002 at 06:12:19PM -0400, Xueying (Libby) SHEN wrote:
> Hi,
> I am doing a project to switch from a home-grown plain-text based database
> to PostgreSQL. Before, we can always check the timestamp of the file to tell
> whether the local info cached is staler than the file or not. So I am
> wondering if there is something similar in PostgreSQL?.

Libby,

the general approach to implement optimistic locking is

1. Read the "last update" timestamp from the database (t1),
together with the data to be edited.
2. Work on data locally.

(some time later:)

3. Obtain a write lock for the "last update" timestamp.
4. Read the "last update" timestamp from the database (t2).
5. If t2 > t1, abort transaction or re-read data, release lock,
report problem, done.
6. Otherwise, go on with the updating.
7. Finally, set the "last update" timestamp to "now".
8. Release the lock.

I don't think there is any built-in support in PostgreSQL for that,
but since you are doing your own locking anyway, you can arrange
an extra table to hold the update timestamp. Or maybe you can add
a timestamp column to the table being updated itself.

Take care -
JPL

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Dalitz 2002-09-09 15:12:30 Re: recommended books???
Previous Message Darren Ferguson 2002-09-09 15:01:51 Re: Debugging plpgsql functions