Skip to content
Advertisement

Search for exact string value in JSON

I have a column stored in JSON that looks like

column name: s2s_payload

Values:

I want to query exact values in the array rather than returning all values for a certain data type. I was using JSON_EXTRACT to get distinct counts.

If I want to filter where “”eventtype””:””search”” how can I do this?

I tried using CAST(s2s_payload AS CHAR) = ‘{“eventtype””:””search”}’ but that didn’t work.

Advertisement

Answer

You need to use json_extract + a CAST to get actual value to compare against:

or, same with json_extract_scalar (and thus with no need for a CAST):

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement