Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of HEX() in SQLite?

Tags:

I have this simple query that returns a bunch of guids as hexadecimal strings:

SELECT HEX(guid) FROM table;

One of them is for instance 43F4124307108902B7A919F4D4D0770D. Then imagine I want to get the record with this guid, so I write a query like this:

SELECT * FROM table WHERE guid = '43F4124307108902B7A919F4D4D0770D';

Of course, this will not work, since the string is directly interpreted as a blob and not converted to it's hex value. I looked here, but couldn't find anything that looks like a method that takes a hexadecimal string and converts it to a blob.

like image 326
Erik B Avatar asked Nov 05 '13 08:11

Erik B


People also ask

How do I reverse a string in SQLite?

Using a common table expression it is possible to reverse a string in SQLite. WITH reverse(i, c) AS ( values(-1, '') UNION ALL SELECT i-1, substr('dlrow olleh', i, 1) AS r FROM reverse WHERE r!= '' ) SELECT group_concat(c, '') AS reversed FROM reverse; Returns hello world .

What does hex do in SQLite?

SQLite hex() function The hex() function interprets its argument as a BLOB and returns a string which is the upper-case hexadecimal rendering of the content of that blob. Integers whose character values (according to the ASCII table) are to be retrieved.


1 Answers

While writing the question I found the answer. I simply had to add an X before the string. Like this:

SELECT * FROM table WHERE guid = X'43F4124307108902B7A919F4D4D0770D';

I figured I should post the question anyway, since non of the "Similar Questions" answers this. What I was looking for was not a function, but a literal and when I realized this I quickly found the answer here.

like image 103
Erik B Avatar answered Sep 23 '22 10:09

Erik B