↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Data Types / Numeric

money

currency amount

Reading PostgreSQL 18.6.

PG10–20 core source inventory. Casts and operator classes show explicitly declared relationships; absent rows do not rule out coercions or indexing through other mechanisms.

Definition

currency amount

money
Catalog name
pg_catalog.money
Type OID
790
Type kind
Base type
Declared length
8 bytes
Storage strategy
plain
Input function
cash_in
Output function
cash_out
Documented declaration
money
Storage Size
8 bytes
Manual description
currency amount
Range
-92233720368547758.08 to +92233720368547758.07

English manual

Read the complete manual section

Read the source definition

8.2. Monetary Types

The money type stores a currency amount with a fixed fractional precision; see Table 8.3. The fractional precision is determined by the database's lc_monetary setting. The range shown in the table assumes there are two fractional digits. Input is accepted in a variety of formats, including integer and floating-point literals, as well as typical currency formatting, such as '$1,000.00'. Output is generally in the latter form but depends on the locale.

Table 8.3. Monetary Types

Name Storage Size Description Range
money 8 bytes currency amount -92233720368547758.08 to +92233720368547758.07

Since the output of this data type is locale-sensitive, it might not work to load money data into a database that has a different setting of lc_monetary. To avoid problems, before restoring a dump into a new database make sure lc_monetary has the same or equivalent value as in the database that was dumped.

Values of the numeric, int, and bigint data types can be cast to money. Conversion from the real and double precision data types can be done by casting to numeric first, for example:

SELECT '12.34'::float8::numeric::money;

However, this is not recommended. Floating point numbers should not be used to handle money due to the potential for rounding errors.

A money value can be cast to numeric without loss of precision. Conversion to other types could potentially lose precision, and must also be done in two stages:

SELECT '52093.89'::money::numeric::float8;

Division of a money value by an integer value is performed with truncation of the fractional part towards zero. To get a rounded result, divide by a floating-point value, or cast the money value to numeric before dividing and back to money afterwards. (The latter is preferable to avoid risking precision loss.) When a money value is divided by another money value, the result is double precision (i.e., a pure number, not money); the currency units cancel each other out in the division.

Catalog attributes

Source bootstrap values for this build. See pg_type for field meanings. Header defaults are included; build-dependent constants remain symbolic. This is not a live-server measurement.

oid
790
descr
monetary amounts, $d,ddd.cc
typacl
_null_
typlen
8
typelem
0
typname
money
typsend
cash_send
typtype
b
typalign
d
typarray
0
typbyval
FLOAT8PASSBYVAL
typdelim
','
typinput
cash_in
typmodin
-
typndims
0
typowner
POSTGRES
typrelid
0
typmodout
-
typoutput
cash_out
typtypmod
-1
typanalyze
-
typdefault
_null_
typnotnull
f
typreceive
cash_recv
typstorage
p
typbasetype
0
typcategory
N
typcollation
0
typisdefined
t
typnamespace
pg_catalog
typsubscript
-
typdefaultbin
_null_
array_type_oid
791
typispreferred
f
array_type_name
_money

Catalog casts 4

Explicit pg_cast records involving this type. PostgreSQL also supports coercions outside pg_cast; an absent row does not prove that a conversion is impossible.

FromToContextMethodFunction
moneynumericAssignmentFunctionnumeric(money)
numericmoneyAssignmentFunctionmoney(numeric)
int4moneyAssignmentFunctionmoney(int4)
int8moneyAssignmentFunctionmoney(int8)

Operator overloads 24

Each operand signature is a separate overload. Catalog implementation functions and result types belong to the same source build.

OperatorLeft operandRight operandResultMeaningImplementation
*moneyfloat4moneymultiplycash_mul_flt4
/moneyfloat4moneydividecash_div_flt4
*float4moneymoneymultiplyflt4_mul_cash
=moneymoneyboolequalcash_eq
<>moneymoneyboolnot equalcash_ne
<moneymoneyboolless thancash_lt
>moneymoneyboolgreater thancash_gt
<=moneymoneyboolless than or equalcash_le
>=moneymoneyboolgreater than or equalcash_ge
+moneymoneymoneyaddcash_pl
-moneymoneymoneysubtractcash_mi
*moneyfloat8moneymultiplycash_mul_flt8
/moneyfloat8moneydividecash_div_flt8
*moneyint8moneymultiplycash_mul_int8
/moneyint8moneydividecash_div_int8
*moneyint4moneymultiplycash_mul_int4
/moneyint4moneydividecash_div_int4
*moneyint2moneymultiplycash_mul_int2
/moneyint2moneydividecash_div_int2
*float8moneymoneymultiplyflt8_mul_cash
*int8moneymoneymultiplyint8_mul_cash
*int4moneymoneymultiplyint4_mul_cash
*int2moneymoneymultiplyint2_mul_cash
/moneymoneyfloat8dividecash_div_cash

Operator classes 1

Operator classes whose declared input type matches this type. Polymorphic classes, casts and expression indexes can provide additional index paths; this list is not an exhaustive yes/no index-support test.

ClassIndex methodInput typeFamilyDefaultStorage type
money_opsbtreemoneybtree/money_opsYesSame as input

Version comparison

PostgreSQL 17.11 → 18.6. Source build identifiers and prose are excluded from attribute changes.

No catalog or structured attribute changes between these samples.

The documentation also differs between these builds; inspect the versioned manual definitions.

Documentation and source

Build
18.6 · https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
Fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Related entries

All Data Types · Download this version as JSON · The first recorded sample does not establish when a type was introduced.