Re: Cast double precision to integer & check for overflow

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Cast double precision to integer & check for overflow
Date: 2013-01-27 03:17:45
Message-ID: ke268p$ab2$1@gonzo.reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2013-01-26, Ian Pilcher <arequipeno(at)gmail(dot)com> wrote:
> I need to cast a double precision into an integer, and I want to check
> that the value will actually fit (modulo rounding).
>
> Coming from a C/Java background, this seems like something that should
> be utterly trivial. In my searching, however, I can't seem to find any
> SQL equivalent of INT_MAX, Integer.MAX_VALUE, etc.
>
> Do I have to hard-code this value?

yes, I think so, the documentation lists the limits here:

http://www.postgresql.org/docs/9.2/interactive/datatype-numeric.html

They are most unlikely to ever change. A new type would probably be added
instead.

--
⚂⚃ 100% natural

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2013-01-27 04:17:08 Re: date_trunc to aggregate by timestamp?
Previous Message Jasen Betts 2013-01-27 03:00:20 Re: Can LC_TIME affect timestamp input?