0

I am somewhat puzzled with the following simple statements.

create table Test(id integer, data json);
insert into Test(id, data) values(1, '{"name": "vova"}');

select * from Test
where  json_extract(data, "$.name") IN ("vova", "mark");

Here select returns nothing. However, the query returns the expected row if i leave a single element in the array:

select * from Test
where  json_extract(data, "$.name") IN ("vova");

'json_extract' and 'where in' dont seem to like each other? Or i'm probably missing something?

Here is a link with an example. Behaviour is the same when i run the queries locally.

1
  • study here, you're missing something database.guide/… Commented Dec 19, 2019 at 3:07

1 Answer 1

1

if you try to evaluate

json_extract(data, "$.name")

-> this will result to "vova"

meaning is with double quotes, treat your IN operator for this scenario as to select the string values, add single quotes.

select * from Test
where  json_extract(data, "$.name") IN ('"vova"', '"mark"');
Sign up to request clarification or add additional context in comments.

1 Comment

oo, yeas, of course... Wonder why it correctly matches/not matches if there is a single element

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.