RE: Re: Unanswered questions about Postgre

From: Roger Wernersson <roger(dot)wernersson(at)mindark(dot)com>
To: "'Edward Q(dot) Bridges'" <ed(dot)bridges(at)buzznik(dot)com>, PostgreSQL general mailing list <pgsql-general(at)postgresql(dot)org>, Roger Wernersson <roger(dot)wernersson(at)mindark(dot)com>
Subject: RE: Re: Unanswered questions about Postgre
Date: 2000-12-12 17:31:43
Message-ID: 5146853DD571D411AC54000102070D610125C6@MINGBGNTS02
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

No, SELECT FOR UPDATE locks the rows matching the constraint and if no rows
match, none are locked.

as in (somewhat oracle syntax)

BEGIN
SELECT 'x' INTO a FROM test WHERE y = 10 FOR UPDATE;
UPDATE test SET z = 12;
EXCEPTION
WHEN no_data_found THEN
INSERT INTO test VALUES (10, 12);
END;

-----Original Message-----
From: Edward Q. Bridges [mailto:ed(dot)bridges(at)buzznik(dot)com]
Sent: den 12 december 2000 17:10
To: PostgreSQL general mailing list; Roger Wernersson
Subject: RE: [GENERAL] Re: Unanswered questions about Postgre

On Tue, 12 Dec 2000 12:04:46 +0100, Roger Wernersson wrote:

>
> I can't BEGIN - SELECT FOR UPDATE - INSERT or UPDATE - COMMIT as someone
> might insert after my SELECT and before my INSERT.
>

correct me if i'm wrong, but a select for update locks the table for
an insert or an update until the end of the transaction.

--e--

> Is there a right solution?
>
> /Roger
>
> -----Original Message-----
> From: Tim Kientzle [mailto:kientzle(at)acm(dot)org]
> Sent: den 12 december 2000 02:10
> To: PostgreSQL general mailing list
> Subject: [GENERAL] Re: Unanswered questions about Postgre
>
>
> > Of course, people really shouldn't be inserting
> > objects which already exist, ...
>
> On the contrary, the best way to test if
> something already exists is to just try the
> INSERT and let the database tell you if
> it's already there. Both faster and more
> reliable than doing SELECT then INSERT.
>
> - Tim
>

Browse pgsql-general by date

  From Date Subject
Next Message Vince Vielhaber 2000-12-12 17:32:46 Re: manuals
Previous Message Bruce Momjian 2000-12-12 17:15:03 Re: manuals