0

i have a column in my users database called "tags" which could look like this:

`[1,2,3,4]`

That array only has numbers.

I am now wondering if I can select from the database where the json array has specific value in it. For example:

`SELECT * FROM users WHERE tags = "HAS 1 IN ARRAY"`

I was testing by just matching the number 1 but then it will probably return values with 10 to 19 if any user has number 10-19 in that array.

1 Answer 1

1

Try this:

SELECT * FROM users WHERE tags REGEXP '[[:<:]]1[[:>:]]';

For more info, see docs Regular Expressions.

PS I would recommend to decompose table, move tags into dependent table. On large table regexp will be slow...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.