0

I want to search the pattern '%myvalue%' in key and value for a json field, return any one that matched.

I use

select * from dialogue_responses where field_rule like '%myvalue%'

it prompts me error

ERROR:  operator does not exist: jsonb ~~ unknown
LINE 1: select * from dialogue_responses where field_rule like '%auf...
                                                          ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

What's he correct way of doing this?

1 Answer 1

1

You can cast into text in the query. Such as

select * from dialogue_responses where field_rule::varchar like '%myvalue%'

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

2 Comments

@VaoTsun: I really didn't this case is answered before. I've just answer base on my experience. Thanks for your advice.
I sent you the link with opinion regarding text vs varchar. its not other answer. I upvoted your answer because this is the easiest way to find match in both keys or values in json. I just was surprised you cast jsonb to varchar, not text.

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.