pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: M Simms <grim@argh.demon.co.uk>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Incrimenting question
Date: Sun, 15 Nov 1998 17:02:55 +0200
Message-ID: <l03110706b2749c1a75c7@[147.233.159.109]> (raw)
In-Reply-To: <199811151318.NAA21545@argh.demon.co.uk>

At 15:18 +0200 on 15/11/98, M Simms wrote:


> I am writing a counter for a webpage and need to know that when I do
>
> update pagestat set hitcount=hitcount+1 where page='main';
>
> that it will count every hit and not just drop hits if 2 people access at
> the same moment. It is a very busy page.

Any statement is inside a transaction. If you have not defined the
transaction explicitly, then each statement is a transaction in its own
right.

Any table accessed from within a transaction is locked for the duration of
the transaction. If the statement was a SELECT statement, the lock is
shared. If it is an UPDATE/INSERT statement, the lock is exclusive.

All this boils down to: If one user enters an update statement on one
table, no other user may "start" the update until the first one has
finished and released the lock. This implies that any simple arithmetic
calculations within a single update statement are, indeed, atomic.

Things to watch out for: SELECTING some data, making a calculation in the
frontend, then updating it. This sort of thing requires a transaction, and
it had better have a LOCK statement in the beginning. But that's not what
you are doing.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





view thread (2+ messages)

Message-ID: <l03110706b2749c1a75c7@[147.233.159.109]>
Permalink:  ../l03110706b2749c1a75c7@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110706b2749c1a75c7@[147.233.159.109]

 · 

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-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, grim@argh.demon.co.uk
  Subject: Re: [SQL] Incrimenting question
  In-Reply-To: <l03110706b2749c1a75c7@[147.233.159.109]>
  References: <199811151318.NAA21545@argh.demon.co.uk> <l03110706b2749c1a75c7@[147.233.159.109]>

* 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