Re: How to use index in WHERE int = float

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to use index in WHERE int = float
Date: 2008-11-05 21:48:57
Message-ID: dcc563d10811051348s1320409cw1bbc712fc4107545@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Nov 5, 2008 at 2:42 PM, Andrus <kobruleht2(at)hot(dot)ee> wrote:
>> Stop trying to compare exact and inexact types?
>>
>> You do realize that a float is not an exact number. What you and I
>> see as 1228137 might really be, internally, 1228136.9999999999999999 ?
>> So it won't get an exact match. What's wrong with trying to match to
>> an exact number instead?
>
> My query contains
>
> '1228137'::float8
>
> I do'nt see
>
> 1228136.9999999999999999
>
> in this query.

Did you read what I wrote? Cause you just repeated it as an argument
against my point.

I don't think you get the difference between exact and inexact types.
Google it for more comprehensive reading on the subject.

> Those strange casts are auto-generated by ODBC parameter passing software
> which I must use so I must live with it.

Sorry to hear that.

PostgreSQL doesn't automatically use indexes when comparing
incompatible types (i.e. exact versus non-exact types) so it's up to
you to use casting to make them match up. There are lots of things
you can do here, but if you're comparing ints with floats you will
eventually be bitten by some comparison that should match but doesn't.
Stick to exact number types if possible.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2008-11-05 21:49:38 Re: How to use index in WHERE int = float
Previous Message Andrus 2008-11-05 21:42:12 Re: How to use index in WHERE int = float