Re: Select for update, locks and transaction levels

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nick Barr" <nick(dot)barr(at)webbased(dot)co(dot)uk>
Cc: "PostgreSQL General ML" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select for update, locks and transaction levels
Date: 2004-02-17 02:42:32
Message-ID: 6162.1076985752@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Nick Barr" <nick(dot)barr(at)webbased(dot)co(dot)uk> writes:
> I personally did not like the look of 1 so I thought about using 2. The
> main reason being there would be no locks that would interfere with
> "updating" the view count because in fact this was just an INSERT
> statement.

INSERTs are good.

> Q2.Will a "group by" used with a "select . for update" lock all the rows
> used for the sum?

No; it won't work at all.

regression=# select hundred,count(*) from tenk1 group by hundred for update;
ERROR: SELECT FOR UPDATE is not allowed with GROUP BY clause
regression=#

However, AFAICS it will not matter if you are using a serializable
transaction. If two such transactions try to delete the same row,
one of them will error out, so you do not need FOR UPDATE.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-02-17 02:48:23 Re: Cascade delete triggers change user credentials
Previous Message Peter Eisentraut 2004-02-17 00:56:43 Re: Fosdem