From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | "Adam Rich" <adam(dot)r(at)indigodynamic(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Locking & concurrency - best practices |
Date: | 2008-01-14 21:38:32 |
Message-ID: | dcc563d10801141338q20261bf0m3f66dcff7186d8c9@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jan 14, 2008 3:31 PM, Adam Rich <adam(dot)r(at)indigodynamic(dot)com> wrote:
> > You should be able to do "select for update" on both parent and child
> > records and get the effect you desire.
> >
>
> I don't think that will work. Let me demonstrate:
> (this is simplified, but sufficient to make my point)
>
> -- Connection 1 --
> begin trans;
>
> select * from parent_tbl
> where id=1 for update;
>
> select count(*) into myvar
> from data_tbl where fk=1;
You're right. with count(*) involved, you won't be able to get an accurate view.
Generally speaking, when you've got to count rows like that, locking
the table is the only thing that works.
That or changing how you process the data.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2008-01-14 21:53:39 | Re: Index trouble with 8.3b4 |
Previous Message | Adam Rich | 2008-01-14 21:31:00 | Re: Locking & concurrency - best practices |