Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector values are changed after inserting them to the database! #46

Closed
Hadryan opened this issue Dec 1, 2022 · 3 comments
Closed

Vector values are changed after inserting them to the database! #46

Hadryan opened this issue Dec 1, 2022 · 3 comments

Comments

@Hadryan
Copy link

Hadryan commented Dec 1, 2022

I inserted this in the database:

INSERT INTO items VALUES
('[0.459, 0.276, 1, -12.803, 1, 0.0804, 0.889, 0.009, 0.217, 0.354, 89.477, 56253, 3]');

After fetching the same vector, the result is as follows:
[0.458999991416931,0.275999993085861,1,-12.8030004501343,1,0.0803999975323677,0.888999998569489,0.00899999961256981,0.216999992728233,0.354000002145767,89.4769973754883,56253,3]

Are they stored as double precision or floats?

@ankane
Copy link
Member

ankane commented Dec 1, 2022

Hey @Hadryan, values are stored as floats (but the same thing could happen with double precision since neither type is exact).

@ankane ankane closed this as completed Dec 1, 2022
@Hadryan
Copy link
Author

Hadryan commented Dec 1, 2022

Ok, but the question is why the values changed?
How to keep the original values?

@ankane
Copy link
Member

ankane commented Dec 1, 2022

Pushed a change in the commit above to make the text representation more friendly. It now uses the same function that Postgres uses for float, so the output is:

[0.459,0.276,1,-12.803,1,0.0804,0.889,0.009,0.217,0.354,89.477,56253,3]

The underlying values are still the same (inexact), so you'll want to use a different type like numeric[] if storing the exact values is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants