0

I would like to perform this query in MYSQL, but the square bracket kills it, assuming that square brackets are reserved?:

select * from policy_data where PolicyData like '%gross_total] => .%'

I'm querying some stored json data, so I'm not sure what my options are! I've tried using back slash in front of it.

like '%gross_total\]%'

I've also tried a replace to no avail:

select * from policy_data where replace(PolicyData, "]", "") like '%gross_total => .%'
James Wilson
  • 809
  • 3
  • 14
  • 25
  • That would be the case for a regex search but is not the case for a LIKE. Do you mean SQL Server? If so http://stackoverflow.com/questions/439495/how-can-i-escape-square-brackets-in-a-like-clause – Alex K. Sep 20 '16 at 13:14
  • Your google search string is `msql escape characters`. – Dan Bracuk Sep 20 '16 at 13:18
  • What does "but of course the square bracket kills it" mean? The bracket has no special meaning in a MySQL LIKE pattern, so it should work fine and the query should get you all rows where PolicyData contains the string 'gross_total] => .%'. – Thorsten Kettner Sep 20 '16 at 13:18
  • Arh shoot! I was looking at how my array looked in a
     output on the page, not how it was stored in JSON in the table :'-(. All I needed to do was: '%gross_total":"."%' - Thank you for helping me spot it.
    – James Wilson Sep 20 '16 at 13:26

1 Answers1

1

Have you tried to escape it ?

select * from policy_data where PolicyData like '%gross_total] \=> .%'
Lucamjj
  • 53
  • 6