sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

sql: Scan error on column index 26, name "xx": converting NULL to string is unsupported

Open jiankunking opened this issue 4 years ago • 6 comments

Can the field value of null in mysql be automatically converted to an empty string instead of reporting an error?

jiankunking avatar Mar 17 '21 07:03 jiankunking

@jiankunking to work with null value you need to use a pointer type. In your case it's *string. There is no magic type conversion in Go. Null and empty string are not the same values.

gurza avatar May 07 '21 15:05 gurza

I feel it is a good idea to convert null to empty string in unsafe mode.

wakels avatar Jul 01 '21 16:07 wakels

A workaround is using IFNULL(expr1, expr2) supported by mysql

jiangke-sr avatar May 27 '22 02:05 jiangke-sr

you can use this tool : https://github.com/jtao539/sqlxp

jtao539 avatar Jul 21 '22 09:07 jtao539

i am facing the same error, if it is the point then why the code is working before hours ??

shamysharma avatar Sep 14 '23 15:09 shamysharma

i just found the solution, error was that some how i post the {Null}, where i need to post Null string type so if you are facing this error go check your sql db and delete the particular column where {null} is stored

shamysharma avatar Sep 14 '23 15:09 shamysharma