Re: On using doubles as primary keys

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Ray Cote <rgacote(at)appropriatesolutions(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Melvin Davidson <melvin6925(at)gmail(dot)com>, Kynn Jones <kynnjo(at)gmail(dot)com>, pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: On using doubles as primary keys
Date: 2015-04-17 18:38:27
Message-ID: 55315323.8010306@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4/17/15 1:10 PM, Ray Cote wrote:
>
>
> (Not an IEEE floating point expert, but...) I've learned the hard way to
> never rely on comparing two floating point numbers for equality -- and
> that's what you are doing if you join on them as primary keys. If you
> must use the underlying numeric data for joining, I'd recommend you do
> something like:
> * output the value to a string (rounded to a specific number of digits)
> * use the textual representation of the number as your primary key.

numeric would probably be more efficient, if you can use that instead.
It does suffer from some of the same issues as floating point (there's
been recent discussion of that on -hackers), but I believe it'd be
better than double.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2015-04-17 18:50:16 Re: Waiting on ExclusiveLock on extension
Previous Message Ray Cote 2015-04-17 18:10:38 Re: On using doubles as primary keys