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

From Matthew Schumacher
Subject Is this a bug? Insert float into int column inserts rounded value instead of error.
Date
Msg-id 46D338A2.8010905@aptalaska.net
Whole thread Raw
Responses Re: Is this a bug? Insert float into int column inserts rounded value instead of error.  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Is this a bug? Insert float into int column inserts rounded value instead of error.  (Andrew Sullivan <ajs@crankycanuck.ca>)
List pgsql-general
List,

One of the reasons why I use postgres is because you can insert data and
it will work or give you an error instead of converting, truncating,
etc... well I found a place where postgres makes an erroneous
assumption and I'm not sure this is by design.

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.

Is this by design?  If so I think it should be changed so that postgres
will always return your data exactly as you entered it if there isn't an
error on insert.

template1=# create table test (number int);
CREATE TABLE
template1=# insert into test (number) values (4.123123123);
INSERT 0 1
template1=# select * from test;
 number
--------
      4
(1 row)


Thanks,
schu

pgsql-general by date:

Previous
From: Kamil Srot
Date:
Subject: Re: Tables dissapearing
Next
From: Tom Lane
Date:
Subject: Re: Tables dissapearing