Re: Get attributes names - Mailing list pgsql-general

From Arthur Zakirov
Subject Re: Get attributes names
Date
Msg-id b7bb9f68-595c-3dff-3dd8-e215eb9b28fe@postgrespro.ru
Whole thread Raw
In response to Get attributes names  (ramsiddu007 <ramsiddu007@gmail.com>)
Responses Re: Get attributes names  (ramsiddu007 <ramsiddu007@gmail.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Raghavendra Rao J S V
Date:
Subject: Need a command to take the backup of the child tables along with itsmaster table.
Next
From: Ron
Date:
Subject: Re: Need a command to take the backup of the child tables along withits master table.