Re: Preventing variables from "rolling over"

Поиск
Список
Период
Сортировка
От Thalis A. Kalfigopoulos
Тема Re: Preventing variables from "rolling over"
Дата
Msg-id Pine.LNX.4.21.0105301208120.317-100000@aluminum.cs.pitt.edu
обсуждение исходный текст
Ответ на Preventing variables from "rolling over"  ("Dr. Evil" <drevil@sidereal.kz>)
Список 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 по дате отправления:

Предыдущее
От: John Burski
Дата:
Сообщение: Things are terribly quiet
Следующее
От: newsreader@mediaone.net
Дата:
Сообщение: Re: DBD::Pg 1.00