Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 977b9e43ddbf791a68788d984b14383d > files > 151

postgresql9.3-docs-9.3.9-1.mga4.noarch.rpm

<!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 9.3.9 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="2015-06-13T20:07:22"></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"
><A
HREF="index.html"
>PostgreSQL 9.3.9 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Numeric Types"
HREF="datatype-numeric.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Data Types</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Character Types"
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.
    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 <TT
CLASS="LITERAL"
>'$1,000.00'</TT
>.
    Output is generally in the latter form but depends on the locale.
   </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
><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
><P
>    Values of the <TT
CLASS="TYPE"
>numeric</TT
>, <TT
CLASS="TYPE"
>int</TT
>, and
    <TT
CLASS="TYPE"
>bigint</TT
> data types can be cast to <TT
CLASS="TYPE"
>money</TT
>.
    Conversion from the <TT
CLASS="TYPE"
>real</TT
> and <TT
CLASS="TYPE"
>double precision</TT
>
    data types can be done by casting to <TT
CLASS="TYPE"
>numeric</TT
> first, for
    example:
</P><PRE
CLASS="PROGRAMLISTING"
>SELECT '12.34'::float8::numeric::money;</PRE
><P>
    However, this is not recommended.  Floating point numbers should not be
    used to handle money due to the potential for rounding errors.
   </P
><P
>    A <TT
CLASS="TYPE"
>money</TT
> value can be cast to <TT
CLASS="TYPE"
>numeric</TT
> without
    loss of precision. Conversion to other types could potentially lose
    precision, and must also be done in two stages:
</P><PRE
CLASS="PROGRAMLISTING"
>SELECT '52093.89'::money::numeric::float8;</PRE
><P>
   </P
><P
>    When a <TT
CLASS="TYPE"
>money</TT
> value is divided by another <TT
CLASS="TYPE"
>money</TT
>
    value, the result is <TT
CLASS="TYPE"
>double precision</TT
> (i.e., a pure number,
    not money); the currency units cancel each other out in the division.
   </P
></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
>