Re: [GENERAL] Cast double precision to integer & check for overflow

From: Alexander Gataric <gataric(at)usa(dot)net>
To: Ian Pilcher <arequipeno(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Cast double precision to integer & check for overflow
Date: 2013-01-26 23:06:42
Message-ID: 643RaZXgh5344M32@ca32.cms.usa.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Just cast to integer. Decimal portion will be lost.

Sent from my smartphone

----- Reply message -----
From: "Ian Pilcher" <arequipeno(at)gmail(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: [GENERAL] Cast double precision to integer & check for overflow
Date: Sat, Jan 26, 2013 3:13 pm

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?

Thanks!

(And yes, I do feel stupid having to ask this question here.)

--
========================================================================
Ian Pilcher arequipeno(at)gmail(dot)com
Sometimes there's nothing left to do but crash and burn...or die trying.
========================================================================

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ian Pilcher 2013-01-26 23:09:47 Re: Cast double precision to integer & check for overflow
Previous Message Ian Pilcher 2013-01-26 21:13:29 Cast double precision to integer & check for overflow