Re: Preventing variables from "rolling over" - Mailing list pgsql-general

From Thalis A. Kalfigopoulos
Subject Re: Preventing variables from "rolling over"
Date
Msg-id Pine.LNX.4.21.0105301208120.317-100000@aluminum.cs.pitt.edu
Whole thread Raw
In response to Preventing variables from "rolling over"  ("Dr. Evil" <drevil@sidereal.kz>)
List 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'tallow it to cycle. When it reaches the maxvalue you'll get an error. 

cheers,
thalis


pgsql-general by date:

Previous
From: John Burski
Date:
Subject: Things are terribly quiet
Next
From: newsreader@mediaone.net
Date:
Subject: Re: DBD::Pg 1.00