pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Gibson (DB Administrator) <postgresql4@ultimeth.com>
To: pgsql-sql@postgresql.org
Subject: Re: Export to XML
Date: Fri, 18 Nov 2005 13:16:21 -0800
Message-ID: <437E44A5.508@ultimeth.com> (raw)
In-Reply-To: <CGEJILOBMIAEJLIJBGFFMEPLCDAA.murray_warren@bah.com>
References: <CGEJILOBMIAEJLIJBGFFMEPLCDAA.murray_warren@bah.com>

On 2005-11-11 10:26, Warren Murray wrote:
> What is the process to export a PostgreSQL table to XML?  How is it done?
> Thanks!
>   

Two ways using PSQL:

1. Select HTML output ("\H" command) and then do a very minor amount of 
post processing (details left to the reader).

2. Select "expanded" output ("\x" command), and then use SED to 
post-format the output into XML:

sed -r 's:^-\[ RECORD (.*) \]-+$:</row>\n<row number="\1">:;s:([^ ]*) 
+\| (.*):  <\1>\2</\1>:;s:^$:</row>:;1s:</row>\n::'

There's probably a cleaner way with AWK, but the above is simple enough 
(your eMail reader may break the above into separate lines at the 
positions where I had a space).  The last two "s" commands just handle 
the first/last line cases.

The only thing the above does not handle is NULL values as distinct from 
zero-length strings.

-- Dean




view thread (3+ messages)  latest in thread

Message-ID: <437E44A5.508@ultimeth.com>
Permalink:  ../437E44A5.508@ultimeth.com/
Also on:    postgresql.org/message-id/437E44A5.508@ultimeth.com

 · 

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: postgresql4@ultimeth.com
  Subject: Re: Export to XML
  In-Reply-To: <437E44A5.508@ultimeth.com>

* 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