Re: Is this a bug? Insert float into int column inserts rounded value instead of error.

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is this a bug? Insert float into int column inserts rounded value instead of error.
Date: 2007-08-27 21:20:31
Message-ID: 20070827212031.GB30834@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)crankycanuck(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kamil Srot 2007-08-27 21:21:34 Re: Tables dissapearing
Previous Message Tom Lane 2007-08-27 21:19:57 Re: Is this a bug? Insert float into int column inserts rounded value instead of error.