我有一个这样的查询:
WITH all_values AS (
SELECT s.projectid AS projectid,
s.prompttype AS prompttype,
(s.attributes::jsonb)->>'prompt' AS prompt,
(s.attributes::jsonb)->>'description' AS description,
(s.attributes::jsonb)->>'topic' AS topic,
(s.attributes::jsonb)->>'context' AS context,
(s.attributes::jsonb)->>'use_case' AS use_case,
(s.attributes::jsonb)->>'subtitle' AS subtitle,
(s.attributes::jsonb)->>'txValues' AS txValues,
(s.attributes::jsonb)->>'flashmode' AS flashmode,
(s.attributes::jsonb)->>'skippable' AS skippable,
(s.attributes::jsonb)->>'videoMaxDuration' AS videoMaxDuration,
(s.attributes::jsonb)->>'defaultCameraFacing' AS defaultCameraFacing,
s.corpuscode AS corpuscode,
s.scriptid AS scriptid,
s.promptnum AS promptnum,
(SELECT ARRAY_AGG(f)
FROM (
SELECT jsonb_object_keys(attributes::jsonb) f
FROM source_table
) AS u) AS others_key
FROM source_table AS s
WHERE
s.prompttype != 'input' AND (s.created > now() - interval '30 minutes' OR s.modified > now() - interval '30 minutes')
GROUP BY s.projectid, s.prompttype, prompt, description, topic, context, use_case, subtitle, txValues, flashmode, skippable, videoMaxDuration, defaultCameraFacing, corpuscode, scriptid, promptnum
)
SELECT * FROM all_values;
在 others_key 列中,我只想显示给定 JSON 中的一般键列表中的一些键(即,不包括列表中的键)。我不知道该怎么做。现在,所有键都简单地显示出来。
找到了解决方案: