Re: Preventing variables from "rolling over"

From: "Thalis A(dot) Kalfigopoulos" <thalis(at)cs(dot)pitt(dot)edu>
To: "Dr(dot) Evil" <drevil(at)sidereal(dot)kz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Preventing variables from "rolling over"
Date: 2001-05-30 16:11:58
Message-ID: Pine.LNX.4.21.0105301208120.317-100000@aluminum.cs.pitt.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 30 May 2001, Dr. Evil wrote:

>
> I assume that if I keep on adding to an INT4, at some point it will
> roll over and become negative, and then if I add some more, it could
> become positive. Is there a way to prevent this? Ie, I would like
> for it to end with an error instead of wrapping around. Or is there a
> way to check for this condition before I do the addition? Is there a
> way to put a constraint on a variable, such that it's always positive?
>
> Thanks

Not exactly, but close: use a sequence instead of an int4 and define the maxvalue to be the max positive for int. Also don't allow it to cycle. When it reaches the maxvalue you'll get an error.

cheers,
thalis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Burski 2001-05-30 16:19:11 Things are terribly quiet
Previous Message Thalis A. Kalfigopoulos 2001-05-30 16:05:03 type conversion fails