Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PostgreSQL解析具有相同xml名称的多个DB列_Xml_Postgresql_Parsing_Xpath - Fatal编程技术网

PostgreSQL解析具有相同xml名称的多个DB列

PostgreSQL解析具有相同xml名称的多个DB列,xml,postgresql,parsing,xpath,Xml,Postgresql,Parsing,Xpath,当xml类似于以下内容时,是否有一种使用xpath解析xml的方法: <foos type="array"> <foo> <name>bar</name> </foo> <foo> <name>bar2</name> </foo> </foos> 酒吧 bar2 基本上,同一名称存在不同的bar值,如上所示。我想将它们存储在

当xml类似于以下内容时,是否有一种使用xpath解析xml的方法:

<foos type="array">
    <foo>
    <name>bar</name>
    </foo>
    <foo>
    <name>bar2</name>
    </foo>
</foos>

酒吧
bar2
基本上,同一名称存在不同的bar值,如上所示。我想将它们存储在postgres表中,以便column1=“_1”,value1=“bar”,column2=“_2”,value2=“bar2”

有什么建议吗


谢谢

我不确定我是否理解您的问题,但您将得到带有XPath表达式的字符串
'bar'

string(/foos/foo[1]/name)
字符串
'bar2'
带有

string(/foos/foo[2]/name)

没有简单的方法可以自动做到这一点;PostgreSQL不擅长生成具有动态列的表。从提取XML到键/值对开始。然后手动或使用
tablefunc
扩展中的
crosstab
函数来旋转它。