pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <ringerc@ringerc.id.au>
To: Victor Sterpu <victor@caido.ro>
Cc: pgsql-sql@postgresql.org
Subject: Re: Selecting data from XML
Date: Tue, 17 Jul 2012 11:23:45 +0800
Message-ID: <5004DAC1.9000301@ringerc.id.au> (raw)
In-Reply-To: <a1dc56fc-9159-4f31-9c94-9c363757f031@caido>
References: <a1dc56fc-9159-4f31-9c94-9c363757f031@caido>

On 07/17/2012 03:56 AM, Victor Sterpu wrote:
> If I have a XML like this
> <?xml version="1.0" encoding="UTF-8"?>
> <Errors>
> <Error  code="CLIN102" validFrom="1980-02-23"/>
> <Error  code="CLIN103" validFrom="1980-02-23" validTo="2012-01-01"/>
> </Errors>
>
> can I write a query that will output the columns names and values like this?
>
> code;validFrom;validTo
> ------------------------------
> CLIN102;1980-02-23;
> CLIN103;1980-02-23;2012-01-01

http://www.postgresql.org/docs/9.1/static/functions-xml.html#FUNCTIONS-XML-PROCESSING

You should be able to do it with some xpath expressions. It probably 
won't be fast or pretty. Consider using PL/Python, PL/perl, PL/Java, or 
something like that to do the processing and return the resultset.

--
Craig Ringer

view thread (2+ messages)

Message-ID: <5004DAC1.9000301@ringerc.id.au>
Permalink:  ../5004DAC1.9000301@ringerc.id.au/
Also on:    postgresql.org/message-id/5004DAC1.9000301@ringerc.id.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ringerc@ringerc.id.au, victor@caido.ro
  Subject: Re: Selecting data from XML
  In-Reply-To: <5004DAC1.9000301@ringerc.id.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox