Re: On using doubles as primary keys - Mailing list pgsql-general

From Jim Nasby
Subject Re: On using doubles as primary keys
Date
Msg-id 55315323.8010306@BlueTreble.com
Whole thread Raw
In response to Re: On using doubles as primary keys  (Ray Cote <rgacote@appropriatesolutions.com>)
List 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


pgsql-general by date:

Previous
From: Ray Cote
Date:
Subject: Re: On using doubles as primary keys
Next
From: Jim Nasby
Date:
Subject: Re: Waiting on ExclusiveLock on extension