Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL IF giving me BLOB

Tags:

mysql

I have the following two lines in an SQL query:

if( tb2.show_count = 0, 'hidden', count( tb1.user_id ) ) as 'count'
if( tb2.show_name = 0, 'hidden', tb1.name ) as 'name'

The first line gives me blob and the second line returns either the name or hidden based on the value of show_name

How do I do the same for the first line? i.e. stop it from giving me a blob and get it to return either the count or hidden based on the value of show_count?

like image 804
oshirowanen Avatar asked Oct 28 '25 23:10

oshirowanen


2 Answers

Try:

if( tb2.show_count=0, 'hidden', cast(count(tb1.user_id) as char(10)) ) as 'count'

- if the results of an if evaluate to different types, they are returned as BLOBs, so the answer is to convert the count to a character type (the same as 'hidden').

In MySQL Workbench, go to: "Edit -> Preferences... -> SQL Queries" OR "Edit -> Preferences... -> SQL Editor" (depending upon what version of Workbench you have).

Check the option 'Treat BINARY/VARBINARY as nonbinary character string' to show the actual value.

like image 29
Vivek Avatar answered Oct 30 '25 14:10

Vivek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!