dbTalk Databases Forums  

Is this safe?

comp.databases.postgresql comp.databases.postgresql


Discuss Is this safe? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jmb@nospam.com
 
Posts: n/a

Default Is this safe? - 12-23-2010 , 11:59 AM






Hello,

we are using postgres for a web application program. My colleague wrote
some code that I suppose is not safe: basically we have a counter, a
integer column in the db, and he choose the value -1 as the value to
represent infinite. The code should decrease the counter value by 1 each
time the user consume a service. I fear this is not much thread safe and
feel uneasy with the solution...should I stop worrying?

regards

Jim

--

Reply With Quote
  #2  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Is this safe? - 12-24-2010 , 12:56 PM






On Thu, 23 Dec 2010 18:59:37 +0100, jmb wrote:

Quote:
Hello,

we are using postgres for a web application program. My colleague wrote
some code that I suppose is not safe: basically we have a counter, a
integer column in the db, and he choose the value -1 as the value to
represent infinite. The code should decrease the counter value by 1 each
time the user consume a service. I fear this is not much thread safe and
feel uneasy with the solution...should I stop worrying?

regards

Jim
Huh? Multiple threads? Threads do not belong to the RDBMS terminology.
RDBMS is all about transactions and sessions. Can you provide a more
detailed explanation of the problem?



--
http://mgogala.byethost5.com

Reply With Quote
  #3  
Old   
jmb@nospam.com
 
Posts: n/a

Default Re: Is this safe? - 12-27-2010 , 06:15 AM



Mladen Gogala <gogala.mladen (AT) gmail (DOT) com> wrote:

Quote:
Huh? Multiple threads? Threads do not belong to the RDBMS terminology.
RDBMS is all about transactions and sessions. Can you provide a more
detailed explanation of the problem?
yep you're right... it's a problem related to the application, not to
the db.

--

Reply With Quote
  #4  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Is this safe? - 01-06-2011 , 09:19 AM



On 27 Dez. 2010, 13:15, j... (AT) nospam (DOT) com wrote:
Quote:
Mladen Gogala <gogala.mla... (AT) gmail (DOT) com> wrote:
Huh? Multiple threads? Threads do not belong to the RDBMS terminology.
RDBMS is all about transactions and sessions. Can you provide a more
detailed explanation of the problem?

yep you're right... it's a problem related to the application, not to
the db.
You did not state exactly in which regard you consider the solution
"unsafe". One thing that strikes immediately is that with a limited
number of permits you would keep decrementing until you hit 0. You
then could easily check whether there are permits left by querying the
value and comparing with 0. That would not work any more for -1
meaning "infinite". To me it seems, NULL would be a better
representation of "infinite". But it all depends what you want to do
with that value. Since we know only little about your problem we
cannot really help you with more specific replies I'm afraid.

Kind regards

robert

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.