I have a postgres jsonb column called items having


I need to compare this whole column with the data


closed as unclear what you're asking by Tom V, dezso, hot2use, Marco, Evan Carroll Aug 31 '18 at 2:12

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Hi there, Welcome to the site. I'm not sure your question is clear at this point. Can you add more details about what you expect to happen. Those 2 code blocks are exactly the same so what are you trying to compare? – Tom V Aug 30 '18 at 13:27
  • If you are sure both arrays hold the items in the same order, you can simply do a items = '[{"id":"","name":""},{"id":"","name":""}]'::jsonb – a_horse_with_no_name Aug 31 '18 at 6:02

If you mean an exact string match then you can do:

SELECT * FROM table where items::text = '[{"id":"","name":""},{"id":"","name":""}]'

Note that JSONB does not necessarily keep the order in the objects the same so it might not work all the time because the order of items might change on the output.

You can lookup the Postgres docs for more advanced JSON operations where you can actually look inside the values.

  • where items = '[{"id":"","name":""},{"id":"","name":""}]'::jsonb would work as well, but only if the items in the array are in the same order. – a_horse_with_no_name Aug 31 '18 at 6:03

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