Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL CONCAT("string",longtext) results in hex string

I'm experiencing a weird hex string result when trying to concat a string with a column that should be of LONGTEXT type.

The query goes like this:

SELECT concat("abc",t.LONGTEXT_VALUE,"cde") FROM mytable t

61626354657374696e67636465

The hex string 61626354657374696e67636465 is the correct value, just in hexadecimal form.

A SELECT on the column itself will return the normal string:

SELECT t.LONGTEXT_VALUE FROM mytable t

Testing
like image 515
Nathan Avatar asked Sep 17 '13 02:09

Nathan


2 Answers

When you concat a number without a cast it returns as a blob. This is intended functionality of MySQL as far as I can tell since, it was reported in this bug thread and they closed it and confirmed it was returning a Blob.

like image 51
Sitch Avatar answered Oct 01 '22 09:10

Sitch


Have you tried casting? Usually works pretty well for me. Example:

SELECT CONCAT("abc",CAST(t.LONGTEXT_VALUE AS CHAR),"cde") FROM mytable t
like image 24
jerdiggity Avatar answered Oct 01 '22 10:10

jerdiggity