Installation
DuckDB
Section titled “DuckDB”Quick Install
Section titled “Quick Install”Install from the community extension repository:
INSTALL monetary FROM community;LOAD monetary;Verify Installation
Section titled “Verify Installation”-- Check extension is loadedSELECT '100 EUR'::monetary;-- Returns: 100.00 EUR
-- Check currency lookup worksSELECT currency_for_country('US');-- Returns: USDPersistent Loading
Section titled “Persistent Loading”Add to your ~/.duckdbrc to load automatically:
INSTALL monetary FROM community;LOAD monetary;Or in Python:
import duckdb
conn = duckdb.connect()conn.execute("INSTALL monetary FROM community")conn.execute("LOAD monetary")
# Now use monetary typesresult = conn.execute("SELECT '99.99 USD'::monetary").fetchone()print(result[0]) # 99.99 USDDependencies
Section titled “Dependencies”The extension auto-installs httpfs for exchange rate functions. No manual setup needed.
PostgreSQL
Section titled “PostgreSQL”Build from Source
Section titled “Build from Source”git clone https://github.com/fyffee/monetary.gitcd monetary/pg_monetary/cppmakesudo make installEnable Extension
Section titled “Enable Extension”CREATE EXTENSION pg_monetary;Verify Installation
Section titled “Verify Installation”-- Check monetary typeSELECT '100 EUR'::monetary;-- Returns: 100.00 EUR
-- Check currency functionsSELECT currency_for_country('DE');-- Returns: EUR
-- Check arithmeticSELECT '50 USD'::monetary + '25 USD'::monetary;-- Returns: 75.00 USDpgxman (Alternative)
Section titled “pgxman (Alternative)”If you use pgxman:
pgxman install pg_monetaryVersion Compatibility
Section titled “Version Compatibility”| Database | Minimum Version |
|---|---|
| DuckDB | 1.4.3+ |
| PostgreSQL | 14+ |
Development Setup
Section titled “Development Setup”For contributors or those who want to build from source:
git clone https://github.com/fyffee/monetary.gitcd monetaryUsing devenv (Recommended)
Section titled “Using devenv (Recommended)”# Install devenv if you don't have itcurl -sfL https://devenv.sh/install.sh | bash
# Enter development environmentdevenv shell
# Build all extensionsbuild-all
# Run teststest-allManual Build (DuckDB)
Section titled “Manual Build (DuckDB)”cd duckdb_monetarymake release GEN=ninja
# Run testsmake test GEN=ninjaManual Build (PostgreSQL)
Section titled “Manual Build (PostgreSQL)”cd pg_monetary/cppmakesudo make install
# Testpsql -c "CREATE EXTENSION pg_monetary;"psql -c "SELECT '100 EUR'::monetary;"