OPENXML in Postgres

前端 未结 2 1898
梦毁少年i
梦毁少年i 2021-01-22 19:04

SQLServer has a very useful function called OPENXML. It works is used like this:

DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc =\'



        
相关标签:
2条回答
  • 2021-01-22 19:27

    I'm sure this code can be improved, but this appears to return the same result in Postgres as the code you posted does in SQL Server.

    WITH test_xml(data) AS (VALUES
      ('<ROOT>
        <Customer CustomerID="VINET" ContactName="Paul Henriot">
           <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00">
              <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/>
              <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/>
           </Order>
        </Customer>
        <Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
           <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00">
              <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/>
           </Order>
        </Customer>
        </ROOT>'::XML)
    )
    SELECT  unnest((xpath('//Customer/@CustomerID', test_xml.data))),
            unnest((xpath('//Customer/@ContactName', test_xml.data)))
    FROM test_xml
    
    0 讨论(0)
  • 2021-01-22 19:36

    This is currently not possible in PostgreSQL (unless someone has written awesome code that he didn't tell anyone about until now).

    0 讨论(0)
提交回复
热议问题