Re: ill-planned queries inside a stored procedure

From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: andrew(at)pillette(dot)com
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: ill-planned queries inside a stored procedure
Date: 2004-08-28 16:35:18
Message-ID: 4130B446.3080006@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

andrew(at)pillette(dot)com wrote:

| Gaetano Mendola <mendola(at)bigfoot(dot)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-----

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Vitaly Belman 2004-08-28 17:41:51 Performance hit on loading from HD
Previous Message andrew 2004-08-28 15:13:37 Re: ill-planned queries inside a stored procedure