Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Precision of data types and functions


  • From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
  • To: Brandon Aiken <BAiken(at)winemantech(dot)com>
  • Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
  • Subject: Re: Precision of data types and functions
  • Date: Mon, 28 Aug 2006 13:21:06 -0500
  • Message-id: <1156789266(dot)10490(dot)16(dot)camel(at)state(dot)g2switchworks(dot)com>

On Mon, 2006-08-28 at 12:28, Brandon Aiken wrote:
> I'm considering migrating our MySQL 4.1 database (barf!) to PostgreSQL 8
> or MySQL 5.  
> 
> The guy who originally designed the system made all the number data
> FLOATs, even for currency items.  Unsurprisingly, we've noticed math
> errors resulting from some of the aggregate functions.  I've learned
> MySQL 5 stores numbers with the DECIMAL data type as text strings, and
> does math at 64-bit precision.  Where can I find information about how
> precise PostgreSQL 8 math is?

Much the same.  I'll let the other poster's reference to numeric types
stand on it's own.  Here's why I'd choose PostgreSQL over MySQL:

smarlowe(at)state:~> mysql test

mysql> select version();
+-----------------+
| version()       |
+-----------------+
| 5.0.19-standard |
+-----------------+
1 row in set (0.00 sec)

mysql> create table test (a numeric(10,2));
Query OK, 0 rows affected (0.05 sec)
 
mysql> insert into test values (123123123123123.2);
Query OK, 1 row affected, 1 warning (0.00 sec)
 
mysql> select * from test;
+-------------+
| a           |
+-------------+
| 99999999.99 |
+-------------+
1 row in set (0.00 sec)

-------------------------------------------------------------

psql test

test=> select version();
                                                 version
----------------------------------------------------------------------------------------------------------
 PostgreSQL 7.4.12 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.3
20040412 (Red Hat Linux 3.3.3-7)

test=> create table test (a numeric(12,2));
CREATE TABLE
test=> insert into test values (123123123123123.2);
ERROR:  numeric field overflow
DETAIL:  The absolute value is greater than or equal to 10^14 for field
with precision 12, scale 2.
test=> select * from test;
 a
---
(0 rows)


I don't trust a database that inserts something other than I told it to
insert and only gives me a warning.

For more info, take a look at these two pages and compare:

http://sql-info.de/mysql/gotchas.html
http://sql-info.de/postgresql/postgres-gotchas.html



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group