K
K
kr_ilya2020-07-25 11:47:35
PostgreSQL
kr_ilya, 2020-07-25 11:47:35

Is it possible to make such a condition for the selection or do I need a separate column?

There is a table in which the item column contains an object in which there is an id field.
5f1bf180484c2032685201.png
Is it possible to make a condition that would compare the id value from this column? Something like this . I think that you can’t do this, because in essence you need to first get the value of the item column, and then compare (this will affect performance), maybe I'm wrong. If you can't directly compare values, then what query can add a new column to a table with id values ​​from an object?
SELECT item FROM items WHERE item.id = 123

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-25
@kr_ilya

Everything is possible, especially if you first read the docs https://www.postgresql.org/docs/12/functions-json.html
And so that there is no "this will affect performance", you can even hang an index on this part of json.
And besides this, it is better to use the type not json, but jsonb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question