Sql XPATH Postgres。使用他的子属性获取节点
我需要你的帮助来解决这个问题。我有一个xml,我需要得到2个属性,第一个属性可以有很多子属性。我需要得到所有的孩子,但与他的父母属性 XML有许多父级,但我只展示我感兴趣的内容Sql XPATH Postgres。使用他的子属性获取节点,sql,xml,postgresql,xpath,Sql,Xml,Postgresql,Xpath,我需要你的帮助来解决这个问题。我有一个xml,我需要得到2个属性,第一个属性可以有很多子属性。我需要得到所有的孩子,但与他的父母属性 XML有许多父级,但我只展示我感兴趣的内容 <group name="Name 1"> <subgroup target="30" show="true"> <subgroup step="0" key="342d8743cd43db67240ad88be462b5ee"/> <subg
<group name="Name 1">
<subgroup target="30" show="true">
<subgroup step="0" key="342d8743cd43db67240ad88be462b5ee"/>
<subgroup step="2" key="342d8743cd43db67240ad88be462b5ee"/>
<subgroup step="5" key="342d8743cd43db67240ad88be462b5ee"/>
</subgroup>
<subgroup target="45" show="true">
<subgroup step="0" key="d0a7c4e08dde0d5ea3558d17bbed1413"/>
</subgroup>
<subgroup target="23" show="true">
<subgroup step="2" key="46c787738274a4bd3968dfbec5b12c7c"/>
</subgroup>
<subgroup target="80" show="true">
<subgroup step="1" key="bf6972c426b1672e7108c1680626698b"/>
</subgroup>
</group>
我尝试使用以下SQL:
选择unnestpath'////subgroup/@target',oc.xml_row::text作为目标
,unnestxpath'///subgroup/subgroup/@step',oc.xml_row::text AS step
从public.target_conf作为oc
用那个SQL,我得到了目标和步骤的笛卡尔积,但若我只放一行,我就得到了所有目标或步骤
我需要和他的“继子”孩子们在一起
示例:我希望sql posgres返回的内容:
目标|步
30 | 0
30 | 2
30 | 5
45 | 0
23 | 2
80 | 1
非常感谢你的帮助 挑选
xpath'@target',子组作为目标,
unnestxpath'subgroup/@step',subgroup::text[]作为步骤
从…起
选择
将xpath'/group/subgroup',oc.xml_行作为子组运行
从…起
public.target_conf作为oc
作为亚组;
给予
请参阅SQL fiddle:
target step
30 0
30 2
30 5
45 0
23 2
80 1