From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: ramsiddu007 <ramsiddu007@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Get attributes names
Date: Thu, 24 Jan 2019 12:54:32 +0300
Message-ID: <b7bb9f68-595c-3dff-3dd8-e215eb9b28fe@postgrespro.ru> (raw)
In-Reply-To: <CA+zEy78hn_k78gY=aMkbS=udEBabpnkaOwZy2MCjOHMdTYRv_A@mail.gmail.com>
References: <CA+zEy78hn_k78gY=aMkbS=udEBabpnkaOwZy2MCjOHMdTYRv_A@mail.gmail.com>
On 24.01.2019 11:54, ramsiddu007 wrote:
> Dear all,
> I hope you are all doing well. Today i got one
> requirement, for that i need attribute names as below example.
>
> Xml:
> <emp>
> <emp_details emp_id="101" emp_name="tom" dept="development"/>
> </emp>
>
> In the above sample input xml, i want attributes list of emp_deails like.
> Attributes
> ___________
> emp_id
> emp_name
> dept
>
>
> Thanking you,
>
In PostgreSQL 11 (and 10 I think) you can do something like this:
=# CREATE TABLE xmldata AS SELECT xml $$
<emp>
<emp_details emp_id="101" emp_name="tom" dept="development"/>
</emp>
$$
as data;
=# SELECT xmltable.*
FROM xmldata,
xmltable('/emp/emp_details/@*' passing data
columns atrr text path 'name()');
atrr
----------
emp_id
emp_name
dept
--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: a.zakirov@postgrespro.ru, ramsiddu007@gmail.com
Subject: Re: Get attributes names
In-Reply-To: <b7bb9f68-595c-3dff-3dd8-e215eb9b28fe@postgrespro.ru>
References: <CA+zEy78hn_k78gY=aMkbS=udEBabpnkaOwZy2MCjOHMdTYRv_A@mail.gmail.com> <b7bb9f68-595c-3dff-3dd8-e215eb9b28fe@postgrespro.ru>
* 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