Suppose that I have some PostgreSQL table ('table_1') that I want to select from in a Python script. This table has a column with JSON data (called 'json_data') like the following, e.g.:
{'4369': 2, '8465': 1, '12561': 1, '12562': 1}
Now I have a list in Python that looks the following:
[4369, 8465, 12561, 16657]
And my goal is to return a JSON/dict from the postgresql table that only contains key/value pairs for which the key is in the Python list for each row. For the above, I would thus expect a JSON returned as:
{'4369': 2, '8465': 1, '12561': 1}
My guess is that it has to look somewhat like this, but I have no clue what has to go at the '...'
SELECT json_data ->> ... IN 'python_list'
FROM table_1
question from:
https://stackoverflow.com/questions/65916759/postgresql-return-a-json-from-json-column-with-only-key-values-for-which-the-key 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…