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

Question: storing and scanning only an exchange rate with pgx #42

Open
jaunt opened this issue Feb 25, 2025 · 0 comments
Open

Question: storing and scanning only an exchange rate with pgx #42

jaunt opened this issue Feb 25, 2025 · 0 comments

Comments

@jaunt
Copy link

jaunt commented Feb 25, 2025

Hello,

Thank you for this library!

I see that the convert function takes in an exchange rate as a string to create an apd.Decimal{} for the calculation.

I'd like to store a currency conversion rate to a postgres table as a numeric and be able to scan it out, without having to use the price structure which includes currency_code which wouldn't apply in this case (all though, maybe having from and to code would make sense).

Do you have a recommendation how I might do this without having to make a new version of github.com/jackc/pgx-shopspring-decimal which uses apd instead?

Maybe if there was currency.Rate as well as currency.Amount?

// Rate stores a decimal exchange rate from and to two currencies.
type Rate struct {
	number       apd.Decimal
	fromCurrencyCode string
	toCurrencyCode string
}

I essentially want to store historical rates accurately. There is an example on this page which has a rate of 0.000000671411306566403 for example:

https://documentation.sas.com/doc/en/fmscdc/5.6/fmspag/p06qd7jikhxltgn1rotrfqopiu4y.htm

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

1 participant