↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / 数据类型

money

currency amount

当前阅读 PG 18·选择有来源记录的版本

此版本暂无所选语言的定义,以下显示原始英文内容。

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
aliases
未知
coverage
source inventory; exact declared input types for operator classes
manual documentation
dedicated family chapter
manual path
datatype-money.html
operator classes
map[opcdefault:t opcfamily:btree/money_ops opcintype:money opckeytype:0 opcmethod:btree opcname:money_ops opcnamespace:pg_catalog opcowner:POSTGRES]
ranges
未知
signature
money

版本定义 PG 18

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.

比较版本

完整来源事实

casts

map[castcontext:a castfunc:numeric(money) castmethod:f castsource:money casttarget:numeric], map[castcontext:a castfunc:money(numeric) castmethod:f castsource:numeric casttarget:money], map[castcontext:a castfunc:money(int4) castmethod:f castsource:int4 casttarget:money], map[castcontext:a castfunc:money(int8) castmethod:f castsource:int8 casttarget:money]

catalog

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

operators

map[descr:multiply oid:843 oprcanhash:f oprcanmerge:f oprcode:cash_mul_flt4 oprcom:*(float4,money) oprjoin:- oprkind:b oprleft:money oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:float4], map[descr:divide oid:844 oprcanhash:f oprcanmerge:f oprcode:cash_div_flt4 oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:float4], map[descr:multiply oid:845 oprcanhash:f oprcanmerge:f oprcode:flt4_mul_cash oprcom:*(money,float4) oprjoin:- oprkind:b oprleft:float4 oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:equal oid:900 oprcanhash:f oprcanmerge:t oprcode:cash_eq oprcom:=(money,money) oprjoin:eqjoinsel oprkind:b oprleft:money oprname:= oprnamespace:pg_catalog oprnegate:<>(money,money) oprowner:POSTGRES oprrest:eqsel oprresult:bool oprright:money], map[descr:not equal oid:901 oprcanhash:f oprcanmerge:f oprcode:cash_ne oprcom:<>(money,money) oprjoin:neqjoinsel oprkind:b oprleft:money oprname:<> oprnamespace:pg_catalog oprnegate:=(money,money) oprowner:POSTGRES oprrest:neqsel oprresult:bool oprright:money], map[descr:less than oid:902 oprcanhash:f oprcanmerge:f oprcode:cash_lt oprcom:>(money,money) oprjoin:scalarltjoinsel oprkind:b oprleft:money oprname:< oprnamespace:pg_catalog oprnegate:>=(money,money) oprowner:POSTGRES oprrest:scalarltsel oprresult:bool oprright:money], map[descr:greater than oid:903 oprcanhash:f oprcanmerge:f oprcode:cash_gt oprcom:<(money,money) oprjoin:scalargtjoinsel oprkind:b oprleft:money oprname:> oprnamespace:pg_catalog oprnegate:<=(money,money) oprowner:POSTGRES oprrest:scalargtsel oprresult:bool oprright:money], map[descr:less than or equal oid:904 oprcanhash:f oprcanmerge:f oprcode:cash_le oprcom:>=(money,money) oprjoin:scalarlejoinsel oprkind:b oprleft:money oprname:<= oprnamespace:pg_catalog oprnegate:>(money,money) oprowner:POSTGRES oprrest:scalarlesel oprresult:bool oprright:money], map[descr:greater than or equal oid:905 oprcanhash:f oprcanmerge:f oprcode:cash_ge oprcom:<=(money,money) oprjoin:scalargejoinsel oprkind:b oprleft:money oprname:>= oprnamespace:pg_catalog oprnegate:<(money,money) oprowner:POSTGRES oprrest:scalargesel oprresult:bool oprright:money], map[descr:add oid:906 oprcanhash:f oprcanmerge:f oprcode:cash_pl oprcom:+(money,money) oprjoin:- oprkind:b oprleft:money oprname:+ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:subtract oid:907 oprcanhash:f oprcanmerge:f oprcode:cash_mi oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:- oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:multiply oid:908 oprcanhash:f oprcanmerge:f oprcode:cash_mul_flt8 oprcom:*(float8,money) oprjoin:- oprkind:b oprleft:money oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:float8], map[descr:divide oid:909 oprcanhash:f oprcanmerge:f oprcode:cash_div_flt8 oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:float8], map[descr:multiply oid:3346 oprcanhash:f oprcanmerge:f oprcode:cash_mul_int8 oprcom:*(int8,money) oprjoin:- oprkind:b oprleft:money oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int8], map[descr:divide oid:3347 oprcanhash:f oprcanmerge:f oprcode:cash_div_int8 oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int8], map[descr:multiply oid:912 oprcanhash:f oprcanmerge:f oprcode:cash_mul_int4 oprcom:*(int4,money) oprjoin:- oprkind:b oprleft:money oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int4], map[descr:divide oid:913 oprcanhash:f oprcanmerge:f oprcode:cash_div_int4 oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int4], map[descr:multiply oid:914 oprcanhash:f oprcanmerge:f oprcode:cash_mul_int2 oprcom:*(int2,money) oprjoin:- oprkind:b oprleft:money oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int2], map[descr:divide oid:915 oprcanhash:f oprcanmerge:f oprcode:cash_div_int2 oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:int2], map[descr:multiply oid:916 oprcanhash:f oprcanmerge:f oprcode:flt8_mul_cash oprcom:*(money,float8) oprjoin:- oprkind:b oprleft:float8 oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:multiply oid:3349 oprcanhash:f oprcanmerge:f oprcode:int8_mul_cash oprcom:*(money,int8) oprjoin:- oprkind:b oprleft:int8 oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:multiply oid:917 oprcanhash:f oprcanmerge:f oprcode:int4_mul_cash oprcom:*(money,int4) oprjoin:- oprkind:b oprleft:int4 oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:multiply oid:918 oprcanhash:f oprcanmerge:f oprcode:int2_mul_cash oprcom:*(money,int2) oprjoin:- oprkind:b oprleft:int2 oprname:* oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:money oprright:money], map[descr:divide oid:3825 oprcanhash:f oprcanmerge:f oprcode:cash_div_cash oprcom:0 oprjoin:- oprkind:b oprleft:money oprname:/ oprnamespace:pg_catalog oprnegate:0 oprowner:POSTGRES oprrest:- oprresult:float8 oprright:money]

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

正文语言: en · 555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f