Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:19:38+00:00 2026-05-30T14:19:38+00:00

I’m looking for something exactly like: XMLTABLE, http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/ Does something like this exist in

  • 0

I’m looking for something exactly like: XMLTABLE, http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/

Does something like this exist in PostgreSQL, or what would be closest?

Or another way, is there a Java library that can accomplish this?


EDIT:

Thanks to Erwin (the answer in his comment is almost precisely what I was looking for).

However, perhaps I could suggest an extension to this.

Consider, we have an xml document like:

<comments photo_id=“123”>
    </comment>this is the first comment</comment>
    </comment>this is the second comment</comment>
</comments>

While, this is a simple example, consider also that “comment” could be quite sophisticated.

My question is now: using the XMLTable function (or Erwin’s implementation), we need to specify a path_to_data i.e. in this case (/comment).

However, if I want my return schema to be something like: [photo_id, comment_text].

There is no way to get data from the elements of the parent of the datanum.

Is it therefore possible to somehow modify your code to do this?
My guess is having something more sophisticated than the xpath function, which essentially returns a subset of data by tracing to the parent.

For example:

<comments photo_id=“123”>
    </comment>this is the first comment</comment>
</comments>

<comments photo_id=“123”>
    </comment>this is the second comment</comment>
</comments>

In this case, we can access “/comments/@photo_id”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:19:39+00:00Added an answer on May 30, 2026 at 2:19 pm

    I finally got some time to take a closer look. From what I gather in your example this might be what you are looking for:

    Test setup:

    I added another node to make my point clear:

    -- DROP TABLE t;
    CREATE TEMP TABLE t (x xml);
    INSERT INTO t VALUES (
    '<tbl>
    <comments photo_id="123">
         <comment>this is the first 123 comment</comment>
         <comment>this is the second 123 comment</comment>
    </comments>
    <comments photo_id="124">
         <comment>this is the first 124 comment</comment>
         <comment>this is the second 124 comment</comment>
         <comment>this is the third 124 comment</comment>
    </comments>
    </tbl>'::xml);
    

    Query:

    SELECT (xpath('./@photo_id', c.node))[1] AS photo_id
         , unnest(xpath('./comment/text()', c.node)) AS descriptor
    FROM  (             
        SELECT unnest(xpath('./comments', x)) AS node
        FROM   t
        ) c;
    

    Result:

     photo_id |           descriptor
    ----------+--------------------------------
     123      | this is the first 123 comment
     123      | this is the second 123 comment
     124      | this is the first 124 comment
     124      | this is the second 124 comment
     124      | this is the third 124 comment
    

    The result looks very simple, but it caused me quite some headache to get there (a while ago, actually).

    Key ingredients are the functions xpath() and unnest(). The trick is to do it in two steps. You can find some more explanation at this related answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to create something EXACTLY like TimePickerDialog (look and feel) in Android, but
http://www.nagare.org/ As far as the type of product and framework usage, think something like
Looking for something like: $(input:radio:checked).previous(name, original_name).attr(name,new_name); I tried a few different seen around here
I was looking for something like Server.MapPath in the ASP.NET realm to convert the
I'm looking for something like: svnserve stop
I'm looking for something like paint.net or Gimp, but for audio files, and runs
I need something exactly like a SQL JOIN which cannot be done with appengine
Okay, so I was looking for something like answered here . The only problem
I've never done code coverage in Python, but I'm looking for something like GCC
Can someone recommend a simple c# code generator. I just looking something with methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.