Re: Converting xml to table with optional elements

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Converting xml to table with optional elements
Date: 2014-11-27 15:03:29
Message-ID: 1417100609569-5828515.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrus Moor wrote
> How to convert xml to table if some elements are optional in xml ?
>
> In XML
>
> /E-Document/Document/DocumentParties/BuyerParty/ContactData/ContactFirstName
> element is optional.
>
> If this is present, code below works OK.
> If ContactFirstName is not present , empty table is returned.
>
> How to extract product code rows if ContactFirstName element is missing ?
> In result ContactFirstName column should have null on other value.

You have to process this in two passes.

First pass you create a table of documents by unnesting the non-optional
Document elements.
Second pass you explode each individual row/document on that table into its
components.

David J.

--
View this message in context: http://postgresql.nabble.com/Converting-xml-to-table-with-optional-elements-tp5828506p5828515.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message rob stone 2014-11-27 16:11:51 Re: Avoiding deadlocks when performing bulk update and delete operations
Previous Message Andrus 2014-11-27 13:54:19 Converting xml to table with optional elements