Re: Converting xml to table with optional elements

From: David Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Converting xml to table with optional elements
Date: 2014-11-28 16:00:52
Message-ID: CAKFQuwa4Bxan4zjw9+ad1MK45PBsgMoq9RO2ve69_06yts_t3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Nov 28, 2014 at 4:17 AM, Andrus <kobruleht2(at)hot(dot)ee> 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 you. I tried code below. John Smith appears in result as "{"John
> Smith"}"
> How to force it to appear as John Smith ?
>

​Subquery the xpath expression to unnest it and apply a LIMIT 1

UPDATE tbl SET ... = (SELECT xpath( tbl.???[...] ) LIMIT 1)

This will cause either the first array element or NULL set to be the given
column's value.

Note that I do not believe your example code is going to work. As I
mentioned you really want to create a table of documents and NOT try to
pair up multiple unnested columns.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Misa Simic 2014-11-28 16:05:25 Re: PG94RC1- plv8 functions - problem with input parameter length
Previous Message Misa Simic 2014-11-28 15:56:01 PG94RC1- plv8 functions - problem with input parameter length