delalli
delalli

Reputation: 67

Getting 'integer out of range' error sqlalchemy

So, I am using odo for data migration but came across this error:

sqlalchemy.exc.DataError: (psycopg2.DataError) integer out of range  

Both the source and the destination tables have the same schema but in the sql statement being executed in the backend the integer values have .0 with them. Like the integer 34 in the source table is shown as 34.0:

[SQL: INSERT INTO table2 (col1, col2,col3) VALUES (%(col1)s, %(col2)s, %(col3)s] 
[parameters: ({'col2' : val2', 'col3' : val3', 'col1' : val1})]

Please let me know if more information is needed.

Upvotes: 1

Views: 2788

Answers (1)

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125204

The sql string should be:

INSERT INTO table2 (col1, col2, col3) VALUES (
    %(col1)s::numeric::int, 
    %(col2)s::numeric::int, 
    %(col3)s::numeric::int
)

If the target column is not nullable and the source value can be None then coalesce it:

    coalesce(%(col1)s::numeric::int, 0), 

Upvotes: 0

Related Questions