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

From: Matthew Schumacher <matt(dot)s(at)aptalaska(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Is this a bug? Insert float into int column inserts rounded value instead of error.
Date: 2007-08-27 20:48:34
Message-ID: 46D338A2.8010905@aptalaska.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kamil Srot 2007-08-27 20:50:53 Re: Tables dissapearing
Previous Message Dann Corbit 2007-08-27 20:48:19 Re: PostgreSQL vs Firebird feature comparison finished