Transform mapped XPath expressions into XML containing relational data

From: Thangalin <thangalin(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Transform mapped XPath expressions into XML containing relational data
Date: 2012-11-26 17:26:34
Message-ID: CAANrE7r=81tCGsr_bNQrotvREiNSD5idk8NarxM4cB8jwnHuMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Is it possible to build an XML (or JSON) document using a map database
columns to XPath expressions? For example:

root > people
person > person
person.first_name -> name/first
person.last_name -> name/last
person.age -> [(at)age]
account.person_id => person.person_id
account > person/account
account.number -> [(at)id]

The arrows have meanings (RHS = right-hand side; LHS = left-hand side):

- > ... Container element (no text values); RHS is the element name.
- -> ... Path to a text value; RHS is the XPath to the element name.
- => ... Join expression; RHS references the attribute in a previously
listed LHS table name.

A PERSON table might resemble:

person_id | first_name | last_name | age
123 | Peter | Parker | 18
456 | James | Jameson | 42

And an ACCOUNT table might resemble:

account_id | person_id | number
1 | 123 | 123456789

Querying the database using the XPath map would produce the following XML
document:

<people>
<person age="18">
<name>
<first>Peter</first>
<last>Parker</last>
</name>
<account id="123456789" />
</person>
<person age="42">
<name>
<first>James</first>
<last>Jameson</last>
</name>
</person></people>

In this case, James Jameson does not have an account and so the
corresponding XML element (account) is not included in the final document.

This would make it trivial to generate a JSON document without changing the
underlying code; whereas, hand-coding the XML document with combinations of
the xml* functions semantically prohibits a direct transmogrification of
the output format.

Thoughts?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2012-11-26 17:31:40 Re: WIP json generation enhancements
Previous Message Magnus Hagander 2012-11-26 16:44:37 Re: 64 bit ints vs libpq-fe.h