0

So basically the column(col1) looks like this:

{"property1": [1, 2], "property2": 3}

So I want to get that array of property1 so that I can check if another number is in that array.

The following is what I want to do:

SELECT *  
FROM table  
WHERE 1 = ANY((col1 ->> 'property1'));

Or something to that effect. The problem is that query brings it back as text, and no matter how I try, it does not want to become an array.

Even tried stuff like this:

SELECT *  
FROM table  
WHERE 1 = ANY((col1 -> 'property1')::int[]);//Says jsonb cant be cast to integer

I tried multiple other things and couldn't get it working.

0

1 Answer 1

1
SELECT *
FROM table
WHERE '1'::jsonb <@ (col1->'property1')
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.