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

Consider changing the way postgres composite types are stored #67

Closed
doughsay opened this issue Apr 25, 2018 · 1 comment
Closed

Consider changing the way postgres composite types are stored #67

doughsay opened this issue Apr 25, 2018 · 1 comment

Comments

@doughsay
Copy link

I'd like to know what the motivation behind storing the numeric amount in postgres composite types as a numeric(20,8) is. With this setup, storing "USD 10.00" for example, turns into "USD 10.00000000" in the db, and then when retrieving it, it retains the precision.

I wanted more control over how much precision is stored for certain columns. I changed the composite money type from what the readme mentions:

CREATE TYPE public.money_with_currency AS (currency_code char(3), amount numeric(20,8))

To this:

CREATE TYPE public.money_with_currency_new AS (currency char(3), amount numeric)

It works much better for my use cases. Is there any reason why this shouldn't be the default?

@kipcole9
Copy link
Owner

@doughsay, its a very reasonable question. My original design decision was based upon discussions with some people in the fintech world who indicated a minimum scale of 8 digits is a requirement. And further googling seems to suggest a widely used definition of numeric(20,8) to cover the ISO4217 currencies.

So the definition in the migration ended up with numeric(20,8). But over the last year I've come to agree with you that the definition is likely better with just numeric since it allows arbitrary precision and scale up to very very large numbers. The only cost is variable sized storage of numbers but that seems a reasonable cost to maintain precision.

Happy to hear comments from any other user of ex_money. If no comment, or unforeseen issue, I will change the definition for the provided migration in the next release.

You are also right that you should find no issues in changing the definition as you suggested above.

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

No branches or pull requests

2 participants