From: | "David Griffiths" <dgriffiths(at)boats(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: SELECT... FOR UPDATE |
Date: | 2002-02-16 01:49:49 |
Message-ID: | a4kdul$2eln$1@jupiter.hub.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
SELECT .... FOR UPDATE;
locks all records returned from the SELECT. Anyone who tries to update any
one of those records will block until you commit, rollback (or the
connection is dropped and a rollback issued).
It will ensure that no-one can modifiy the record(s).
David
"GB Clark" <postgres(at)vsservices(dot)com> wrote in message
news:20020215155107(dot)1e405665(dot)postgres(at)vsservices(dot)com(dot)(dot)(dot)
> Hi,
>
> Can anyone give me a couple of examples or a explanation of select for
update is supposed to work?
>
> I've looked in the manual and the locking stuff is confusing (or it could
just be me not understanding..))
> and neither of my SQL books go into any type of detail on locking.
>
> What I want to do is select a record, do something and then update that
record to reflect the outcome
> of the processing with 0% chance of another process doing the same thing.
Is this possiable?
>
> my idea:
>
> BEGIN
> SELECT * FROM table1 WHERE record_id = '290202' FOR UPDATE
> -- Do processing here
> UPDATE table1 SET flag1 = '11' WHERE record_id = '290202'
> COMMIT
>
> Just looking for more information....
>
> Thanks,
>
> GB
>
> --
> GB Clark II | Roaming FreeBSD Admin
> gclarkii(at)VSServices(dot)COM | General Geek
> CTHULU for President - Why choose the lesser of two evils?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2002-02-16 04:36:30 | Re: |
Previous Message | Tom Lane | 2002-02-16 00:55:17 | Re: No Interval Conversion Function in 7.2?!!? |