| From: | Ragnar <gnari(at)hive(dot)is> |
|---|---|
| To: | Ash Grove <ash_grv7(at)yahoo(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: is an explicit lock necessary? |
| Date: | 2006-05-04 18:59:58 |
| Message-ID: | 1146769198.31874.3.camel@localhost.localdomain |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On fim, 2006-05-04 at 11:10 -0700, Ash Grove wrote:
> Hi,
>
> Does beginning a transaction put locks on the tables
> queried within the transaction?
>
> In the example below, is #2 necessary? My thought was
> that I would need to use an explicit lock to make sure
> that the sequence value I'm selecting in #4 is the
> same one that is generated from #3. I'm worried about
> another instance of the application doing an insert on
> table1 between #3 and #4.
>
> 1) From my app, I turn off autocommit.
> 2) I lock table1 in access exclusive mode
> 3) I do an insert into table1 which generates a
> primary key via nextval on sequence1
> 4) I grab grab the primary key value via currval on
> sequence1
> 5) I do an insert on table2 which includes table1's
> primary key so I can join the records later.
> 6) I manually commit
No. The locking is not necessary.
currval is defined to return the value most recently obtained by nextval
for this sequence in the current session.
see:
http://www.postgresql.org/docs/8.1/interactive/functions-sequence.html
gnari
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Catalin Pitis | 2006-05-04 19:00:00 | Re: Connecting to Postgres from other machines (outside localhost) |
| Previous Message | Stephan Szabo | 2006-05-04 18:50:24 | Re: is an explicit lock necessary? |