Search Shortcut cmd + k | ctrl + k
monetary

Currency-aware monetary values with parsing, arithmetic, and real-time exchange rates

Maintainer(s): onnimonni

Installing and Loading

INSTALL monetary FROM community;
LOAD monetary;

Example

-- Parse monetary values
SELECT '100 EUR'::monetary;
SELECT '$50.25'::monetary;

-- Arithmetic with currency validation
SELECT '100 EUR'::monetary + '50 EUR'::monetary;

-- Fetch real-time exchange rates (requires http_request extension)
SELECT * FROM ecb_exchange_rates();
SELECT * FROM freegold_exchange_rates() WHERE data_source = 'yahoo_finance';

About monetary

The monetary extension provides:

  • Currency-aware monetary type with 70+ currencies (ISO 4217)
  • Safe arithmetic with currency mismatch detection
  • 10 exchange rate sources (ECB, BOC, RBA, CNB, SNB, Norges Bank, TwelveData, OXR, GoldAPI, FreeGold)
  • Precious metals (XAU, XAG, XPT, XPD) with weight unit conversion
  • Cryptocurrencies (BTC, ETH)

For more information, see the repository.