From: Gaetano Mendola <mendola@bigfoot.com>
To: andrew@pillette.com
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: ill-planned queries inside a stored procedure
Date: Sat, 28 Aug 2004 18:35:18 +0200
Message-ID: <4130B446.3080006@bigfoot.com> (raw)
In-Reply-To: <200408281513.i7SFDbh04877@pillette.com>
References: <200408281513.i7SFDbh04877@pillette.com>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
andrew@pillette.com wrote:
| Gaetano Mendola <mendola@bigfoot.com> 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-----
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: mendola@bigfoot.com, andrew@pillette.com
Subject: Re: ill-planned queries inside a stored procedure
In-Reply-To: <4130B446.3080006@bigfoot.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