<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Monetary Types</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 8.4.8 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Data Types" HREF="datatype.html"><LINK REL="PREVIOUS" TITLE="Numeric Types" HREF="datatype-numeric.html"><LINK REL="NEXT" TITLE="Character Types" HREF="datatype-character.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2011-04-15T03:27:09"></HEAD ><BODY CLASS="SECT1" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" >PostgreSQL 8.4.8 Documentation</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="datatype-numeric.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="datatype.html" >Fast Backward</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" >Chapter 8. Data Types</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="datatype.html" >Fast Forward</A ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="datatype-character.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="DATATYPE-MONEY" >8.2. Monetary Types</A ></H1 ><P > The <TT CLASS="TYPE" >money</TT > type stores a currency amount with a fixed fractional precision; see <A HREF="datatype-money.html#DATATYPE-MONEY-TABLE" >Table 8-3</A >. The fractional precision is determined by the database's <A HREF="runtime-config-client.html#GUC-LC-MONETARY" >lc_monetary</A > setting. Input is accepted in a variety of formats, including integer and floating-point literals, as well as typical currency formatting, such as <TT CLASS="LITERAL" >'$1,000.00'</TT >. Output is generally in the latter form but depends on the locale. Non-quoted numeric values can be converted to <TT CLASS="TYPE" >money</TT > by casting the numeric value to <TT CLASS="TYPE" >text</TT > and then <TT CLASS="TYPE" >money</TT >, for example: </P><PRE CLASS="PROGRAMLISTING" >SELECT 1234::text::money;</PRE ><P> There is no simple way of doing the reverse in a locale-independent manner, namely casting a <TT CLASS="TYPE" >money</TT > value to a numeric type. If you know the currency symbol and thousands separator you can use <CODE CLASS="FUNCTION" >regexp_replace()</CODE >: </P><PRE CLASS="PROGRAMLISTING" >SELECT regexp_replace('52093.89'::money::text, '[$,]', '', 'g')::numeric;</PRE ><P> </P ><P > Since the output of this data type is locale-sensitive, it might not work to load <TT CLASS="TYPE" >money</TT > data into a database that has a different setting of <TT CLASS="VARNAME" >lc_monetary</TT >. To avoid problems, before restoring a dump into a new database make sure <TT CLASS="VARNAME" >lc_monetary</TT > has the same or equivalent value as in the database that was dumped. </P ><DIV CLASS="TABLE" ><A NAME="DATATYPE-MONEY-TABLE" ></A ><P ><B >Table 8-3. Monetary Types</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><THEAD ><TR ><TH >Name</TH ><TH >Storage Size</TH ><TH >Description</TH ><TH >Range</TH ></TR ></THEAD ><TBODY ><TR ><TD >money</TD ><TD >8 bytes</TD ><TD >currency amount</TD ><TD >-92233720368547758.08 to +92233720368547758.07</TD ></TR ></TBODY ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="datatype-numeric.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="datatype-character.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Numeric Types</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="datatype.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Character Types</TD ></TR ></TABLE ></DIV ></BODY ></HTML >