我有一个包含JSON类型字段的表,其中包含数据数组:
Column | Type
-------------------+---------
id | integer
user_id | uuid
changes | jsonb
exercise_entry_id | integer
changes
字段包含一个JSON对象列表。
对于数据清理任务,我需要将changes
字段的内容作为聚合进行连接,并返回另一个非嵌套的JSON数组。
假设数据库包含以下行:
id | user_id | changes | exercise_entry_id
---+---------+-----------------+---------------------
1 | foo | ['a', 'b'] | 3
2 | foo | ['c', 'd'] | 3
我需要一个按user_id和exercise_entry_id分组的结果,其中更改按以下方式连接。
user_id | changes | exercise_entry_id
--------+-----------------------------+---------------------------
foo | ['a', 'b', 'c', 'd'] | 3