Re: How can I know if a row is Locked?

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How can I know if a row is Locked?
Date: 2007-04-13 11:48:54
Message-ID: 20070413114854.GM24558@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am Fri, dem 13.04.2007, um 4:27:34 -0700 mailte Carlos Santos folgendes:
> How can I know if a row is locked by another transaction.
> I have in a transaction like that:
>
> BEGIN;
> SELECT * FROM compels.teste WHERE id = '1' FOR UPDATE;
>
> PS1: where id is the primary key.
> PS2: The COMMIT command is done after a long time.
>
> In this case the row with the primary-key equals to '1' will be locked to other
> transactions until the COMMIT command be executed.
> So, how can I detect if this row is locked?

You can call the insert with 'for update nowait' and catch the error, if
an error occurs.

Maybe there are better solutions...

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Sullivan 2007-04-13 11:49:19 Re: A long-running transaction
Previous Message Marcin Stępnicki 2007-04-13 11:48:52 Re: How can I know if a row is Locked?