Re: Select for update, locks and transaction levels - Mailing list pgsql-general

From Tom Lane
Subject Re: Select for update, locks and transaction levels
Date
Msg-id 6162.1076985752@sss.pgh.pa.us
Whole thread Raw
In response to Select for update, locks and transaction levels  ("Nick Barr" <nick.barr@webbased.co.uk>)
List pgsql-general
"Nick Barr" <nick.barr@webbased.co.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

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Fosdem
Next
From: Tom Lane
Date:
Subject: Re: Cascade delete triggers change user credentials