Question

In a database (MySql) I am storing some string values and checking for the uniqueness of those strings before storing them.

For a fast string comparison (I mean check if the incoming string already exists in the DB before recording) I want to hast the incoming string (MD5), split the string into 2 equal parts, convert them into 2 bigints, store them separately along with the string, and when a record request arrives I want to search for these 2 bigints in a multiple column index. (ofcourse i will get the incoming string, MD5 that string, calculate the 2 bigint parts then query the database)

But the "line 3" below produces an interesting error in my "MySql Routine".

...
declare mystring varchar(3000); -- line 1
declare md5bigint1value bigint; -- line 2
...

set md5bigint1value = conv(substring((md5(mystring)),1,16),16,10); -- line 3
...

At "line 3" it says: Error Code: 1264. Out of range value for column 'md5bigint1value' at row 1

Does anybody know why this is happening?

Please let me know if you need any more info. Thank you very much.

Était-ce utile?

La solution

CONV, when used with a positive to_base, converts to an unsigned value, while BIGINT is signed. An unsigned 64-bit value won't necessarily fit into a signed 64-bit variable.

If to_base is a negative number, N is regarded as a signed number. Otherwise, N is treated as unsigned.

What you want to do is use -10 for a destination base, that is;

set md5bigint1value = conv(substring((md5(mystring)),1,16),16,-10); -- line 3

SQLfiddle to test with (10 won't work, -10 will).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top