在PostgreSQL 9.4中,我如何检索这样的json对象:
parentTableFirstProp: 'string',
parentToChildReference: [
{childTableFirstProp: 'another string'},
{childTableFirstProp: 'yet another string'}
}]
而不是:
[{
parentTableFirstProp: 'string',
childTableFirstProp: 'another string',
},{
parentTableFirstProp: 'string',
childTableFirstProp: 'yet another string'
}]
我是否总是必须进行2个选择查询,并通过使用别名来插入一个?
更新1
我尝试使用JOIN
:
SELECT
"public"."ParentTable".*,
"public"."ChildTable".*
FROM
"public"."ParentTable"
RIGHT JOIN "public"."ChildTable"
ON "public"."ParentTable"."childReference"
我将尝试解释ParentTable
和ChildTable
包含的内容:
ParentTable = {
id: 111
parentTableFirstProp: 'string',
parentToChildReference: [222, 333]
}
ChildTable = [{
id: 222,
childTableFirstProp: 'another string'
},{
id: 333,
childTableFirstProp: 'yet another string'
}]