X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8045C5E46D2 for ; Sat, 28 Aug 2004 13:35:30 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16701-09 for ; Sat, 28 Aug 2004 16:35:29 +0000 (GMT) Received: from pns.mm.eutelsat.org (pns.mm.eutelsat.org [194.214.173.227]) by svr1.postgresql.org (Postfix) with ESMTP id 1F4FF5E46F2 for ; Sat, 28 Aug 2004 13:35:20 -0300 (ADT) Received: from nts-03.mm.eutelsat.org (localhost [127.0.0.1]) by pns.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i7SGYXr13347; Sat, 28 Aug 2004 18:34:34 +0200 Received: from [127.0.0.1] (accesspoint.mm.eutelsat.org [194.214.173.4]) by nts-03.mm.eutelsat.org (8.11.6/linuxconf) with ESMTP id i7SGZOV28763; Sat, 28 Aug 2004 18:35:24 +0200 Message-ID: <4130B446.3080006@bigfoot.com> Date: Sat, 28 Aug 2004 18:35:18 +0200 From: Gaetano Mendola User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: andrew@pillette.com Cc: "pgsql-performance@postgresql.org" Subject: Re: ill-planned queries inside a stored procedure References: <200408281513.i7SFDbh04877@pillette.com> In-Reply-To: <200408281513.i7SFDbh04877@pillette.com> X-Enigmail-Version: 0.85.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/414 X-Sequence-Number: 8050 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 andrew@pillette.com wrote: | Gaetano Mendola wrote .. | |>Hi all, |>do you know any clean workaround at ill-planned queries inside a stored |>procedure? | I use "EXECUTE" inside a stored procedure for just this purpose. This is | not the same as PREPARE/EXECUTE, it lets you send an arbitrary string as | SQL within the procedure. You have to write the query text on the fly in | the procedure, which can be a little messy with quoting and escaping. | Yes I knew, I wrote "clean workaround" :-) I hate write in function piece of code like this: ~ [...] ~ my_stm := ''SELECT '' || my_operation || ''( '' || a_id_transaction; ~ my_stm := my_stm || '', '' || a_id_contract; ~ my_stm := my_stm || '', '' || quote_literal(a_date) || '') AS res''; ~ FOR my_record IN EXECUTE my_stm LOOP ~ IF my_record.res < 0 THEN ~ RETURN my_record.res; ~ END IF; ~ EXIT; ~ END LOOP; ~ [...] note also that useless loop that is needed to retrieve the value! Regards Gaetano Mendola -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBMLRE7UpzwH2SGd4RAv0TAJ9+IokZjaXIhgV5dOH86FCvzSnewQCgwqxD nuW9joHmPxOnlRWrvhsKaag= =Axb7 -----END PGP SIGNATURE-----