Re: Problems with PL/PGSQL - functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Problems with PL/PGSQL - functions
Дата
Msg-id 26109.1010941173@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Problems with PL/PGSQL - functions  ("Unnikrishnan Menon" <unnikrishnan.menon@chennai.transys.net>)
Список pgsql-sql
"Unnikrishnan Menon" <unnikrishnan.menon@chennai.transys.net> writes:
>     b. query1 :=3D '' Select xyz as variable from S_''|| nextval(sequence)|=
> |'' where abc =3D (some counter value) '' ;
>         Execute query1;

You can't use EXECUTE for a SELECT (no way to retrieve the result) nor
for a SELECT INTO (annoying implementation restriction that should be
removed someday).  The only way to get a result from a
dynamically-constructed select statement is to use FOR ... EXECUTE.

You do need to use EXECUTEs with any query involving a dynamically
generated table name, so you'll just have to grin and bear it.

But --- does the table actually have to be handled that way?  If you
need exactly one such temp table per session, you could use "CREATE TEMP
TABLE" and give the table a fixed name.  Then you could skip all the BS
with EXECUTE.  Note however that it has to be per session; dropping and
recreating the table mid-session won't work since already-cached query
plans in your plpgsql functions will still point to the old temp table.
        regards, tom lane


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

Предыдущее
От: "Ross J. Reedstrom"
Дата:
Сообщение: Re: Problems with PL/PGSQL - functions
Следующее
От: Sharon Cowling
Дата:
Сообщение: Problem with unique index