database - Need to join double precision foreign key with integer primary key -


what highest performing query joins double precision foreign key integer primary key. tables data vendor, , i'd rather not convert column data type.

in example, fk double precision , pk integer.

should use round?

select this_table.pk, other_table.some_col this_table inner join other_table on other_table.pk = round(this_table.fk)  

or maybe no conversion needed?

thanks.

you can join integers , doubles directly. mysql manage type casting itself. round(double) returns double anyway, not integer.

the joins succeed doubles represent integer. means can directly join 6.0 6; can't directly join 6.000001 6.

if want join 6.000001 6, cast double integer join values in range 6.0 <= 6 < 7.0 . . .

select ... table_with_integers n inner join table_with_doubles d    on cast(d.double_column unsigned integer) = n.integer_column ... 

or use round() join values in range 6.0 <= 6 < 6.5.

the type cast makes more sense if doubles supposed represent integers. if doubles supposed represent integers, shouldn't getting values 6.000001 in first place.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -