2007/5/13, Wallace Reis <[EMAIL PROTECTED]>:

Em anexo uma funcao em plperlu. Vale lembrar que a versao 8.3 tera isso
nativamente.


Wallace, muito legal essa função em PL/PerlU!

Em anexo algumas alterações que eu fiz nela, para receber o nome do esquema
e um filtro para a seleção. Por sorte, fui testar a função e existiam
tabelas homônimas no meu banco. Daí resolvi inventar moda. Ah, a sobrecarga
com 1 e 2 parâmetros fica por conta de duas funções em linguagem SQL.


rodrigo=# \d nova
           Table "public.nova"
Column |         Type          | Modifiers
--------+-----------------------+-----------
id     | integer               | not null
nome   | character varying(50) | not null
Indexes:
   "nova_pkey" PRIMARY KEY, btree (id)

rodrigo=# SELECT * FROM nova;
id |   nome
----+----------
 1 | primeiro
 2 | segundo
 3 | terceiro
(3 rows)


rodrigo=# SELECT table_to_xml('public', 'nova', 'id = 2');
                                       table_to_xml
-------------------------------------------------------------------------------------------------
<nova xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <row>
       <id>2</id>
       <nome>segundo</nome>
   </row>
</nova>
(1 row)


rodrigo=# SELECT table_to_xml('public', 'nova');
                                       table_to_xml
-------------------------------------------------------------------------------------------------
<nova xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <row>
       <id>1</id>
       <nome>primeiro</nome>
   </row>
   <row>
       <id>2</id>
       <nome>segundo</nome>
   </row>
   <row>
       <id>3</id>
       <nome>terceiro</nome>
   </row>
</nova>
(1 row)


rodrigo=# SELECT table_to_xml('nova');
                                       table_to_xml
-------------------------------------------------------------------------------------------------
<nova xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <row>
       <id>1</id>
       <nome>primeiro</nome>
   </row>
   <row>
       <id>2</id>
       <nome>segundo</nome>
   </row>
   <row>
       <id>3</id>
       <nome>terceiro</nome>
   </row>
</nova>
(1 row)


--
Atenciosamente,

Rodrigo Hjort
Icewall Tecnologias
http://www.icewall.com.br

Attachment: table_to_xml.sql
Description: Binary data

_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a