-2

I have some columns VARCHAR which contains JSON content with relation to other rows of the same table, and i need to convert this into comma separated keys to use a WHERE IN.

Example column content:

[{"manuel":"Manuel Fernandez"},{"marta":"Marta Flores"}]

And what i need is:

manuel,marta

This is part of a bigger query where this conversion should be applied to more than one column and thats why i think the best solution is doing this using Mysql REGEX

Update 1

Mysql version 5.7.25

Ricardo Albear
  • 496
  • 8
  • 26

1 Answers1

1

You need to remove [, ], {", and everything from ":" to the next } from the string.

regexp_replace(columnName, '\\[|\\]|\\{"|":"[^}]*\\}', '')

You need MySQL 8.0 to get a built-in REGEXP_REPLACE() function. If you're using an older version, see How to do a regular expression replace in MySQL?

Barmar
  • 741,623
  • 53
  • 500
  • 612