Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread David Johnston
On Fri, Nov 28, 2014 at 10:47 AM, Andrus wrote: > Hi! > > Thank you. > > Instead of defining an xpath for fields define one that captures the xml >> pertaining to the data that would belong to >> a single record.How to create single xpath or xsl which assigns values to >> all columns in Postgres

Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread Andrus
Hi! Thank you. Instead of defining an xpath for fields define one that captures the xml pertaining to the data that would belong to a single record.How to create single xpath or xsl which assigns values to all columns in Postgres table ? I havent found such sample. Samples which I have found c

Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread David Johnston
On Fri, Nov 28, 2014 at 9:40 AM, Andrus wrote: > Hi! > > Thank you. >>Subquery the xpath expression to unnest it and apply a LIMIT 1 > > UPDATE tbl SET ... = (SELECT xpath( tbl.???[...] ) LIMIT 1) > > I used unnest() : > ​Sorry, I meant to say (SELECT unnest(xpath(tbl.???[...])) LIMIT 1

Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread Andrus
Hi! Thank you. >Subquery the xpath expression to unnest it and apply a LIMIT 1 > UPDATE tbl SET ... = (SELECT xpath( tbl.???[...] ) LIMIT 1) I used unnest() : update temprid set ContactFirstName =unnest(xpath( '/E-Document/Document/DocumentParties/BuyerParty/ContactData/ContactFirstName/

Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread David Johnston
On Fri, Nov 28, 2014 at 4:17 AM, Andrus wrote: > Hi! > > 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. >> > > Thank

Re: [GENERAL] Converting xml to table with optional elements

2014-11-28 Thread Andrus
Hi! 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. Thank you. I tried code below. John Smith appears in result as "{"J

Re: [GENERAL] Converting xml to table with optional elements

2014-11-27 Thread David G Johnston
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 tabl