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.

asked Feb 27, 2016 at 16:29

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

answered Feb 27, 2016 at 17:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.