Re: ill-planned queries inside a stored procedure

Поиск
Список
Период
Сортировка
От Gaetano Mendola
Тема Re: ill-planned queries inside a stored procedure
Дата
Msg-id 4130B446.3080006@bigfoot.com
обсуждение исходный текст
Ответ на Re: ill-planned queries inside a stored procedure  (andrew@pillette.com)
Список pgsql-performance
-----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-----


В списке pgsql-performance по дате отправления: