Postgres Long Datatype

Hello there, I have a field coming from a third-party and its type is long what Ecto datatype should I use to be able to save the field in postgres as long? Since int produces this error

** (DBConnection.EncodeError) Postgrex expected an integer in -2147483648..2147483647, got 8510569521150675000. Please make sure the value you are 
passing matches the definition in your table or in your query or convert the value accordingly

Thanks in advance!

Just provide a value in the range. Ecto/Postgrex should do the right thing then.

1 Like

I think the value is coming from a 3rd party, @aligredo can’t control that.

The value you’re trying to save @aligredo is larger than even a bigint column, i think you’ll need to use a decimal column type


Oh, that way round… I thought the DB schema was provided by a third party and now the OP can’t insert their own values…


Basically I see 5 possibilities for you (random order):

  • Clamp the value that it fits your database
  • Modulo the value such that it fits your database
  • drop the value
  • Tell the third party to provide valid data
  • Change your database schema to fit the given values.

Can you try with decimal data type?

1 Like

Thank you. I will try using the :decimal datatype, and I’ll let you know the result.

1 Like

The :decimal datatype worked perfectly, thank you all.