Re: Is this a bug? Insert float into int column inserts rounded value instead of error. - Mailing list pgsql-general

From Andrew Sullivan
Subject Re: Is this a bug? Insert float into int column inserts rounded value instead of error.
Date
Msg-id 20070827212031.GB30834@phlogiston.dyndns.org
Whole thread Raw
In response to Is this a bug? Insert float into int column inserts rounded value instead of error.  (Matthew Schumacher <matt.s@aptalaska.net>)
List pgsql-general
On Mon, Aug 27, 2007 at 12:48:34PM -0800, Matthew Schumacher wrote:
> When inserting a float such as 4.12322345 into a int column postgres
> inserts 4 instead of returning an error telling you that your value
> won't fit.  I would much rather have the error and check for it since I
> can be sure I'll get 4.12322345 back out if I didn't get an error on insert.

If you quote it, it works.  That is:

testing=# SELECT 4.123123123::int;
 int4
------
    4
(1 row)

testing=# SELECT '4.123123123'::int;
ERROR:  invalid input syntax for integer: "4.123123123"

A

--
Andrew Sullivan  | ajs@crankycanuck.ca
I remember when computers were frustrating because they *did* exactly what
you told them to.  That actually seems sort of quaint now.
        --J.D. Baldwin

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is this a bug? Insert float into int column inserts rounded value instead of error.
Next
From: Erik Jones
Date:
Subject: Re: Tables dissapearing