2017-02-27 30 views
0

有表mydocs(id序列,docform int,內容文本)。在postgresql中使用xpath_table?

SELECT * FROM 
    xpath_table('id','content','mydocs', 
       '/tutorial/author|/tutorial/title', 
       'true') 
    AS t(id int, author text, title text, docform int) 

我有(ID,作者和書名,docform爲0 /空)的圖像看到

enter image description here

如何從在選擇mydocs docform。

docform是表mydocs的列,就像上面說的那樣。

enter image description here

+1

請發佈您的XML結構示例,並解釋XML的哪一部分應該是'docform' – har07

+0

添加的圖像發佈。 docform是mydocs中的列。 –

回答

0

由於docform你試圖來選擇從一個單獨的列的解決可能需要外界xpath_table()實現,例如,通過增加JOINmydocs表本身,並從那裏docform

SELECT t.*, m.docform 
    FROM mydocs m 
    INNER JOIN LATERAL 
     xpath_table('id','content','mydocs', 
        '/tutorial/author|/tutorial/title', 
        'true') 
     AS t(id int, author text, title text) ON m.id = t.id 

sqlfiddle demo

+0

非常感謝你! –