Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group