You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when loading specific values in fields of type {:map, :float} #2637
Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): PostgreSQL 9.6.7
Ecto version (mix deps): master branch
Database adapter and version (mix deps): postgrex 0.14.0-dev
Operating system: Debian Jessie
Current behavior
When I have a schema with a field of type {:map, :array}, some values are parsed to exponential floats and are saved as integers in the database.
For example, %{"50" => 416500.0} fails, because it is saved as an integer 416500, even after Float.parse(416500), which returns an exponential form for it. I don't know if it has something to do with the jsonb fields, but for simple floatfields it works.
changed the title [-]Loading error with specific values in fields of type {:map, :float}[/-][+]Error when loading specific values in fields of type {:map, :float}[/+]on Aug 2, 2018
@michalmuskala the worst part is that Postgres is semantically correct, there are no integers/floats in JSON. I guess we need to do casting here on Ecto side.
Any chance that this problem is also happening with {:array, :float}? I have a issue with an array of floats sometimes failing to be inserted. (Elixir 1.7.3, ecto, 2.2)
Reacted by Mateus Kahler, Tallys Martins and Gabriel Alves
Activity
[-]Loading error with specific values in fields of type {:map, :float}[/-][+]Error when loading specific values in fields of type {:map, :float}[/+]wojtekmach commentedon Aug 2, 2018
It's curious that the integration test fails on pg but passes on mysql.
tallysmartins commentedon Aug 3, 2018
@wojtekmach good point! but actually I didn't add a value for field to a test case for mysql, just for pg 🤔
wojtekmach commentedon Aug 3, 2018
@tallysmartins
integration_test/cases/repo.exsand others are shared between different adapters, see e.g.: https://github.com/elixir-ecto/ecto/blob/master/integration_test/mysql/all_test.exs#L12michalmuskala commentedon Aug 3, 2018
It seems this is an issue with how postgresql handles JSON with floats in exponential notation.
josevalim commentedon Aug 3, 2018
@michalmuskala the worst part is that Postgres is semantically correct, there are no integers/floats in JSON. I guess we need to do casting here on Ecto side.
michalmuskala commentedon Aug 3, 2018
Should we do for
{:map, _}type the same thing we do for{:embed, _}in here? https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/adapters/sql.ex#L47josevalim commentedon Aug 3, 2018
@michalmuskala if it fixes the bug, sure. :) We may need to do a couple extra things though.
Share loading/dumping logic between embed and typed maps, closes #2637
Share loading/dumping logic between embed and typed maps, closes #2637
hoarf commentedon Feb 19, 2019
Any chance that this problem is also happening with {:array, :float}? I have a issue with an array of floats sometimes failing to be inserted. (Elixir 1.7.3, ecto, 2.2)
Share loading/dumping logic between embed and typed maps, closes elix…