From: | Alexander Solianic <solianic(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: JDBC and SQL |
Date: | 2001-06-26 14:10:09 |
Message-ID: | 3b3896f8@news.telekom.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ed Murray wrote:
> Could anybody explain a good way of doing the following.
> I would like to read an integer value from a database and then
> update the database value by adding a specified figure to it.
> The addition must be done before any other query can else can access
> this value. i.e. preferably in the same operation.
> I would like to do this using JDBC and try and keep it cross
> database compatible.
>
> Any help would be greatly appreciated.
>
> --
> Ed Murray
> Avenue Network Services
> hns(at)optushome(dot)com(dot)au
> + 61 2 94162140
>
>
>
>
Assume you have table `mytable' with two integer
columns: `x' and `y'. To atomicaly update `x' in row
with y == 123 you may use something like this
(just SQL, not JDBC):
select x from mytable where y=123 for update; /* locks row */
/* do something with `x' value, calculate `newvalue' */
update mytable set x=newvalue where y=123;
commit;
PS
autocommit must be `false'.
--
Regards,
Alexander Solianic
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Solianic | 2001-06-26 14:11:37 | Re: Where are User Defined Functions Stored? |
Previous Message | Martijn van Oosterhout | 2001-06-26 14:05:41 | Why is NULL not indexable? |