我的 Postgres 数据库的主表与其他表有几个一对多的关系,每个关系都由一个[*]_references表连接。我需要一个结果,该结果与其他表的结果一起以 JSON 形式返回。我可以加入以获得我想要的数据,如下所示:
SELECT ft.id, json_agg(genres) AS genres
FROM ft_references ft
INNER JOIN genre_references gr ON gr.reference_id = ft.id
INNER JOIN genres_catalog genres ON gr.genre_id = genres.id
WHERE ft.id = 2 GROUP BY ft.id;
id | genres
----+--------------------------------------------------
2 | [{"id":1,"name":"Action","other_info":null}, +
| {"id":2,"name":"Adventure","other_info":null}, +
| {"id":5,"name":"Comedy","other_info":null}, +
| {"id":8,"name":"Drama","other_info":null}, +
| {"id":10,"name":"Fantasy","other_info":null}, +
| {"id":13,"name":"Horror","other_info":null}, +
| {"id":25,"name":"War","other_info":null}]
(1 row)
Run Code Online (Sandbox Code Playgroud)
同样,我的第二组结果:
SELECT ft.id, json_agg(tales) AS tales
FROM ft_references ft
INNER JOIN tale_references tr …Run Code Online (Sandbox Code Playgroud) 我的解析器可能会遇到“2:37PM”(由“H:mma”解析)或“02:37PM”(由“hh:mma”解析)。如何在不使用 try-catch 的情况下解析两者?
当我出错时,我会收到这样的错误:
发现冲突:字段 AmPmOfDay 0 与源自 02:37 的 AmPmOfDay 1 不同