Re: SELECT FOR UPDATE

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: jose <jose(at)sferacarta(dot)com>
Cc: Postgres <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT FOR UPDATE
Date: 2001-08-23 01:01:10
Message-ID: 200108230101.f7N11Br15817@jupiter.us.greatbridge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jose wrote:
> Hi all,
>
> I'm trying SELECT FOR UPDATE
> but I have a problem with locks.
>
> example:
> I have two users accessing to the same records, say...
>
> user1:
> DELECT * FROM table WHERE field=value FOR UPDATE
> ---------------------------------------------------------------------------
>
> user2:
> DELECT * FROM table WHERE field=value FOR UPDATE
> at this point user2 can't do nothing except waiting for user1 unlock recors.
>
> My question is:
>
> - Is it possible to know in advance if the records of a given query are
> locked, to prevent to be locked for ever?

Well, first of all the scientists are still unsure if this
universe will exist forever or not. So even if you find a way
to let your system survive the sun becoming a red giant and
so on, there's still uncertainty if it'll take forever or
not.

Anyway, the answer is no. Standard SQL doesn't have any
mechanism to check wether a given row is locked or to force a
query to fail with an error in the case a required lock isn't
available immediately.

But the question itself tells that you're about to implement
a major design error in your application. Holding database
locks during user interaction IS A BAD THING. Never, never
ever do it that way. And anybody telling you something
different is an overpaid idiot.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lee Harr 2001-08-23 01:28:41 Re: Group by date
Previous Message Lee Harr 2001-08-23 00:57:32 Re: Group by date