1

In PostgreSQL 9.5 I use jsonb column called user_tag. This column has multi dimensional array like this:

[{"id": 1, "tag": "@xang"}, {"id": 2, "tag": "@wang"}]

I want to get when id is equal to 1. I can do this by following query:

SELECT * FROM mydb AS f WHERE f.user_tag #>> '{0,id}' = '1'

But, I have to provide 0 as a key. I want to search all id columns and return matched table rows. If I already know 0, why would i search in first place.

Any idea will be appreciated.

Note: SELECT * FROM mydb AS f WHERE f.user_tag ->> 'id' = '1' is not worked.

1 Answer 1

0

I found it myself. I wil llet you guys know so may other people get use it.

SELECT * FROM mydb AS f WHERE f.user_tag @> '[{"id":1}]'

That' s it. I can now get rows contains id=1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.