Jump to content

How to remove [] from a query result


Recommended Posts

I have a query that returns a result enclosed in [ ] and I want to remove these brackets 


I can successfully get rid of the right or left bracket but not both using a trim


TRIM(Trailing ']' FROM g.field_value) AS Genre 


but if i add a TRIM(leading '['     i get an error 


if the characters were both the same then TRIM(both ']' will work but they are not


Do you have a solution 

Link to comment
Share on other sites

I agree - it could be an indication that something is wrong - but data can be sourced from all sorts of places, sometimes it is a case of just having to deal with it.  It's especially the case when the data is from a third party and there may be nothing you can do with the source data, you massage it to fit into what you need.  

Working with data loads can provide a great insight into what people try and do and your left with the impression that relying on people to do anything correctly and consistently is like trying to juggle water.

Link to comment
Share on other sites

If the data comes from a third party (which is pure speculation), then you sanitize it before putting it into the database. Even the weakest programming language is far better at string operations than any MySQL hack.


In any case, I'd be careful with literal answers. Users often fail to show their actual problem and only post random ideas they've come up with. Implementing those ideas may not solve the problem at all.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.