Skip to content
Advertisement

How do I parameterize this jsonb array contains query?

I have the following sql:

Which gives me (as expected):

789019 | 789019

Now, I need to parameterize the query but am unable to:

I get an empty row and that’s because it is literally searching for "$1". I try to remove the double quotes then it complains

I’m not sure how to resolve this one.

Advertisement

Answer

If you just want to check if an array contains a given value, you can use ? instead of @>.

That would look like:

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