Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BC4EB9FB591 for ; Tue, 31 Jul 2007 11:15:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 12864-01 for ; Tue, 31 Jul 2007 11:15:14 -0300 (ADT) X-Greylist: delayed 00:05:01.052483 by SQLgrey-1.7.5 Received: from fw-bonn.bund.de (mail2-bonn.bund.de [194.95.179.138]) by postgresql.org (Postfix) with ESMTP id F096A9FB378 for ; Tue, 31 Jul 2007 11:15:13 -0300 (ADT) Received: from m2.mfw.bn.ivbb.bund.de (localhost [127.0.0.1]) by fw-bonn.bund.de (8.13.8/8.13.8) with ESMTP id l6VEAA10016816 for ; Tue, 31 Jul 2007 16:10:10 +0200 (CEST) Received: (from localhost) by m2.mfw.bn.ivbb.bund.de (MSCAN) id 3/m2.mfw.bn.ivbb.bund.de/smtp-gw/mscan; Tue Jul 31 16:10:10 2007 Date: Tue, 31 Jul 2007 16:10:03 +0200 (CEST) From: Andreas Tille X-X-Sender: tillea@wr-linux02 To: pgsql-performance@postgresql.org Subject: Using EXECUTE in a function Message-Id: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-OriginalArrivalTime: 31 Jul 2007 14:10:42.0764 (UTC) FILETIME=[94B4F0C0:01C7D37C] X-TM-AS-Product-Ver: SMEX-7.0.0.1499-5.0.1021-15332.002 X-TM-AS-Result: No--6.921300-8.000000-31 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/437 X-Sequence-Number: 26121 Hi, I have found under 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). 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 ... ) 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. Kind regards and thanks for any help Andreas. -- http://fam-tille.de