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

feat(electric): Add support for the float4 column type #657

Merged
merged 7 commits into from
Nov 29, 2023

Conversation

alco
Copy link
Member

@alco alco commented Nov 13, 2023

No description provided.

Copy link

linear bot commented Nov 13, 2023

VAX-846 Implement support for float4 type

Reference: https://electric-sql.slab.com/posts/data-validation-supporting-more-postgres-types-tpegouhj#h1sz5-supporting-more-basic-postgres-types-in-electric.

  • Implement server-side validation that ensures a given string-formatted number can fit into float4. In Elixir, This can presumably be achieved with <<f::float-32>> = <<num::float-32>> where num is a floating-point number to be validated. If I understand correctly, the pattern matching will fail if num does not fit into a 32-bit float. Even if that's not the case, the comparison f === num should finish the job for sure.
  • Look into how the [extra_float_digits](https://www.postgresql.org/docs/11/datatype-numeric.html#DATATYPE-FLOAT) setting affects the values in the logical replication stream.
  • Add float4 to the list of supported data types
  • Mention float4 in the data type docs
  • Add an E2E test that verifies syncing of float4 values

@alco alco force-pushed the alco/vax-846-add-support-for-float4 branch from 99b93ef to 54c6fa0 Compare November 13, 2023 15:40
Copy link
Contributor

@magnetised magnetised left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fun one. great stuff. are we numerically complete now?

@alco
Copy link
Member Author

alco commented Nov 23, 2023

that's a fun one. great stuff. are we numerically complete now?

Good one. We still have Postgres' decimal / numeric data type to work on.

Copy link
Contributor

@icehaunter icehaunter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

alco and others added 7 commits November 29, 2023 12:15
This PR adds client-side support for float4.
Numbers provided by the user are rounded to the nearest float4
representation using `Math.fround()`.
Similarly, when numbers are read from a float4 column in the DB they are
rounded to the nearest float4 representation.
This would not strictly be necessary if all writes happen through the
DAL but because of SQLite's dynamic typing, users can write
larger/smaller numbers to float4 columns in which case we would read
numbers that fall out of range.
@alco alco force-pushed the alco/vax-846-add-support-for-float4 branch from 8db1206 to 136d192 Compare November 29, 2023 10:44
@alco alco merged commit b6e589d into main Nov 29, 2023
14 checks passed
@alco alco deleted the alco/vax-846-add-support-for-float4 branch November 29, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants