这是一个奇怪的错误。我有以下查询返回我想要的数据:
SELECT
coalesce(block.name, 'Other') as name,
json_agg(set.data) as sets
FROM
set
FULL OUTER JOIN block ON set.block_id = block.id
GROUP BY block.id
请注意"设置"是一个具有完全有效数据的json列。现在,我想要做的就是按照"设置"的值对输出进行排序。列,所以我添加了ORDER BY子句:
SELECT
coalesce(block.name, 'Other') as name,
json_agg(set.data) as sets
FROM
set
FULL OUTER JOIN block ON set.block_id = block.id
GROUP BY block.id
ORDER BY sets->0->>'releaseDate'
它以某种方式告诉我"设置"不存在:
为什么会发生这种情况?如何让它发挥作用?
编辑是否有帮助,这里有一个可用于构建我所拥有的相同模式的pastebin:http://pastebin.com/UZa0jZXi
这可能不相关,但如果我根本不使用任何json运算符,并尝试按" set" (不是那会起作用),Postgres至少承认该列存在:
SELECT
coalesce(block.name, 'Other') as name,
json_agg(set.data) as sets
FROM
set
FULL OUTER JOIN block ON set.block_id = block.id
GROUP BY block.id
ORDER BY sets