Select Output in XML format

Started by Adarsh Sharmaover 14 years ago6 messagesgeneral
Jump to latest
#1Adarsh Sharma
adarsh.sharma@orkash.com

Dear all,

Today I need to write the output of an postgres table into XML format.
I think there is an easiest way to do this but not able to find it.

In mysql there is simple query for that :

mysql -X -e "select * from db_name.master" > /hdd2-1/test.xml

In postgres , i find some XML data types but how we can put our select
output into xml file.

Thanks

#2Craig Ringer
craig@2ndquadrant.com
In reply to: Adarsh Sharma (#1)
Re: Select Output in XML format

On 8/09/2011 2:41 PM, Adarsh Sharma wrote:

Dear all,

Today I need to write the output of an postgres table into XML format.
I think there is an easiest way to do this but not able to find it.

http://www.postgresql.org/docs/current/static/functions-xml.html

Use the query_to_xml or table_to_xml functions.

--
Craig Ringer

#3Chetan Suttraway
chetan.suttraway@enterprisedb.com
In reply to: Adarsh Sharma (#1)
Re: Select Output in XML format

On Thu, Sep 8, 2011 at 12:11 PM, Adarsh Sharma <adarsh.sharma@orkash.com>wrote:

Dear all,

Today I need to write the output of an postgres table into XML format.
I think there is an easiest way to do this but not able to find it.

In mysql there is simple query for that :

mysql -X -e "select * from db_name.master" > /hdd2-1/test.xml

In postgres , i find some XML data types but how we can put our select
output into xml file.

Thanks

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/**mailpref/pgsql-general&lt;http://www.postgresql.org/mailpref/pgsql-general&gt;

Please go through below link:

http://www.postgresql.org/docs/9.0/static/xml2.html
http://developer.postgresql.org/pgdocs/postgres/functions-xml.html

Regards,
Chetan

--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb

#4Adarsh Sharma
adarsh.sharma@orkash.com
In reply to: Craig Ringer (#2)
Re: Select Output in XML format

Thanks I am trying as below ;

db_name=# select table_to_xml(tbl master, nulls boolean, tableforest
boolean, targetns text);
ERROR: syntax error at or near "master"
LINE 1: select table_to_xml(tbl master, nulls boolean, tableforest b...
^
Do I need to use both functions

Craig Ringer wrote:

Show quoted text

On 8/09/2011 2:41 PM, Adarsh Sharma wrote:

Dear all,

Today I need to write the output of an postgres table into XML format.
I think there is an easiest way to do this but not able to find it.

http://www.postgresql.org/docs/current/static/functions-xml.html

Use the query_to_xml or table_to_xml functions.

--
Craig Ringer

#5Chetan Suttraway
chetan.suttraway@enterprisedb.com
In reply to: Adarsh Sharma (#4)
Re: Select Output in XML format

On Thu, Sep 8, 2011 at 12:53 PM, Adarsh Sharma <adarsh.sharma@orkash.com>wrote:

Thanks I am trying as below ;

db_name=# select table_to_xml(tbl master, nulls boolean, tableforest
boolean, targetns text);
ERROR: syntax error at or near "master"
LINE 1: select table_to_xml(tbl master, nulls boolean, tableforest b...
^
Do I need to use both functions

Check the below syntax:

--already created base table
pg=# desc base;
Table "public.base"
Column | Type | Modifiers
--------+---------+-----------
a | integer |
Number of child tables: 1 (Use \d+ to list them.)

pg=# select table_to_xml( 'base', true, true, '');
                         table_to_xml
--------------------------------------------------------------
 <base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                             +
   <a>1</a>                                                  +
 </base>                                                     +
                                                             +
 <base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
                                                             +
   <a>2</a>                                                  +
 </base>                                                     +
                                                             +

(1 row)

--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb

#6Chetan Suttraway
chetan.suttraway@enterprisedb.com
In reply to: Adarsh Sharma (#4)
Re: Select Output in XML format

On Thu, Sep 8, 2011 at 12:53 PM, Adarsh Sharma <adarsh.sharma@orkash.com>wrote:

Thanks I am trying as below ;

db_name=# select table_to_xml(tbl master, nulls boolean, tableforest
boolean, targetns text);
ERROR: syntax error at or near "master"
LINE 1: select table_to_xml(tbl master, nulls boolean, tableforest b...
^
Do I need to use both functions

Please go through the documentation listed at:

http://developer.postgresql.org/pgdocs/postgres/functions-xml.html

Craig Ringer wrote:

On 8/09/2011 2:41 PM, Adarsh Sharma wrote:

Dear all,

Today I need to write the output of an postgres table into XML format.
I think there is an easiest way to do this but not able to find it.

http://www.postgresql.org/**docs/current/static/functions-**xml.html&lt;http://www.postgresql.org/docs/current/static/functions-xml.html&gt;

Use the query_to_xml or table_to_xml functions.

--
Craig Ringer

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/**mailpref/pgsql-general&lt;http://www.postgresql.org/mailpref/pgsql-general&gt;

--
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb