Hacker News new | ask | show | jobs
by skissane 1210 days ago
> If we used a composite currency type, the currency_type field would be highly redundant.

It can help prevent the bug in which someone adds up multiple currencies without conversion.

“25 USD + 25 EUR” will either fail or work via some currency conversion routine.

“25 + 25” will produce a meaningless and useless wrong answer.

1 comments

Yes, this is exactly what I’ve done previously. For example, I implemented a sum() aggregate function that took “monetary” (currency + value) composite types and raised an exception if the currencies were not all the same.