pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Andreas Tille <tillea@rki.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Using EXECUTE in a function
Date: Wed, 1 Aug 2007 08:58:50 +0530
Message-ID: <b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0707311529490.15955@wr-linux02>
References: <Pine.LNX.4.64.0707311529490.15955@wr-linux02>

On 7/31/07, Andreas Tille <tillea@rki.de> wrote:
http://www.physiol.ox.ac.uk/Computing/Online_Documentation/postgresql/plpgsql.html#PLPGSQL-OVERVIEW
>
>      Note:  The PL/pgSQL  EXECUTE statement is not related to the EXECUTE
>             statement supported by the PostgreSQL server. The server's EXECUTE
>             statement cannot be used within PL/pgSQL functions (and is not needed).

If I read the documentation correctly, EXECUTE is not needed because
query plans are generally cached within pl/pgsql after the first
execution of the function.

> I'm especially stumbling over the "is not needed" part.  My plan
> is to write a server side function (either SQL or pgsql) that wraps
> the output of a PREPAREd statement but I have no idea how to do this.
>
> The final task is to obtain some XML for of my data via a simple shell script
> that contains
>
>          psql -t MyDatabase -c 'SELECT * FROM MyFunction ($1, $2);'
>
> The task of MyFunction($1,$2) is to wrap up the main data into an XML
> header (just some text like
>      <?xml version="1.0" encoding="ISO-8859-1"?>
>        ...
> ) around the real data that will be obtained via a PREPAREd statement that is
> declared like this
>
>     PREPARE xml_data(int, int) AS ( SELECT ... WHERE id = $1 AND source = $2 );
>
> where "..." stands for wrapping the output into xml format.
>
> I don't know whether this is a reasonable way.  I know how to solve this
> problem when using a pgsql function and preparing the output as a text
> string but I learned that PREPAREd statements might be much more clever
> performance wise and thus I wonder whether I could do it this way.

prepared statements are the fastest possible way to execute queries
but generally that extra speed is not measurable or only useful under
specific conditions.  also, prepared statements can't be folded into
queries the way functions can:

select xml_data(foo, bar) from baz;

so, I'd stick with the function approach (I think that's what you are
asking).  If you are doing XML work you may be interested in the
upcoming xml features of 8.3:

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

merlin



view thread (2+ messages)

Message-ID: <b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com>
Permalink:  ../b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com

 · 

reply

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-performance@postgresql.org
  Cc: mmoncure@gmail.com, tillea@rki.de
  Subject: Re: Using EXECUTE in a function
  In-Reply-To: <b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com>
  References: <Pine.LNX.4.64.0707311529490.15955@wr-linux02> <b42b73150707312028s208ac126l42073fd16402a46c@mail.gmail.com>

* 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