OPENXML in Postgres

前端 未结 2 1899
梦毁少年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
      ('
        
           
              
              
           
        
        
           
              
           
        
        '::XML)
    )
    SELECT  unnest((xpath('//Customer/@CustomerID', test_xml.data))),
            unnest((xpath('//Customer/@ContactName', test_xml.data)))
    FROM test_xml
    

提交回复
热议问题