Re: EXTPROC External Procedure - Mailing list pgsql-general

From Pavel Stehule
Subject Re: EXTPROC External Procedure
Date
Msg-id Pine.LNX.4.44.0502092016150.7904-100000@kix.fsv.cvut.cz
Whole thread Raw
In response to EXTPROC External Procedure  (Roy Souther <roy@silicontao.com>)
List pgsql-general
Hello,

code for genereting xml:

CREATE OR REPLACE FUNCTION ext.xml(varchar) RETURNS text AS $$
   use DBI; use XML::Generator::DBI; use XML::Handler::YAWriter;
   my $rv = spi_exec_query("SELECT current_setting('client_encoding'), " .
                           "current_database()", 1);
   my $encoding = lc($rv->{rows}[0]->{current_setting[5~});
   my $cdb = $rv->{rows}[0]->{current_database};
   my $dbh = DBI->connect ("DBI:Pg:dbname=$cdb", "", "", { RaiseError =>
1, PrintError => 0});
   my $ya = XML::Handler::YAWriter->new (Encoding=>$encoding,
        Pretty => {PrettyWhiteNewline => 1, PrettyWhiteIndent => 1,});
   my $gen = XML::Generator::DBI->new (Handler => $ya, dbh => $dbh,
                           ByColumnName => 1, ShowColumns => 1,);
   $gen->execute ($_[0]);
   $dbh->disconnect ();
   return join('',@{$ya->{Strings}});
$$ LANGUAGE plperlu;
SELECT ext.xml('SELECT * FROM ext.jmena LIMIT 10');

Sending mail, or uploud file via HTTP isn't problem. PL/Perlu works very
fine.

Regards
Pavel Stehule


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Understanding EXPLAIN ANALYZE output
Next
From: "Gavin M. Roy"
Date:
Subject: Re: PHP/PDO Database Abstraction Layer