Hi Michael,
Thanks for your time.
I have figured out the problem. My error is not related to the data type,
as you pointed out. It is related to the definition of the TABLE column
repeatedly and inconsistently (meaning: initially I define the column as
Integer in the database, then I changed to Numeric but it is not changed,
due to my bad coding).
Regards,
Chengjun
On Tuesday, July 14, 2015 at 1:47:08 AM UTC+2, Michael Bayer wrote:
On 7/13/15 7:02 PM, Chengjun JIN wrote:
Hi all,
I am trying to save data into postgresql via sqlchemy ORM. I encountered
an error below: sqlalchemy.exc.DataError: (psycopg2.DataError) integer
out of range
I pinpoint the place where it goes wrong. I have a large number which is
2468432255.0.
If I change to smaller number like 468432255.0, then it works.
The thing confused me is that: I define the column as volume =
Column(Numeric). As far as I understand, Numeric should be able to handle
this large number. Additionally, I tried other data type like BigInt
etc... They all gave me the same error.
I can't reproduce that. Here's a test:
from sqlalchemy import create_engine, Numeric, MetaData, Table, Column
m = MetaData()
t = Table('x', m, Column('data', Numeric))
e = create_engine(postgresql://scott:tiger@localhost/test, echo=True)
c = e.connect()
tr = c.begin()
m.create_all(c)
c.execute(
t.insert(),
{data: 2468432255.0}
)
What is the actual NUMERIC type in the schema? If you make a NUMERIC type
with too low of a precision/scale, the number will be rejected. example:
from sqlalchemy import create_engine, Numeric, MetaData, Table, Column
m = MetaData()
t = Table('x', m, Column('data', Numeric(6, 2)))
e = create_engine(postgresql://scott:tiger@localhost/test, echo=True)
c = e.connect()
tr = c.begin()
m.create_all(c)
c.execute(
t.insert(),
{data: 2468432255.0}
)
output:
sqlalchemy.exc.DataError: (psycopg2.DataError) numeric field overflow
DETAIL: A field with precision 6, scale 2 must round to an absolute value
less than 10^4.
[SQL: 'INSERT INTO x (data) VALUES (%(data)s)'] [parameters: {'data':
2468432255.0}]
Please adapt the test above to illustrate how you're getting your error
exactly.
Any idea?
Thanks,
Chengjun
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an
email to sqlalchemy+...@googlegroups.com javascript:.
To post to this group, send email to sqlal...@googlegroups.com
javascript:.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.