Re: plpgsql variable trouble

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: plpgsql variable trouble
Дата
Msg-id 4824.975598330@sss.pgh.pa.us
обсуждение исходный текст
Ответ на plpgsql variable trouble  (Phil Steinke <lintec@engsoc.queensu.ca>)
Список pgsql-general
Phil Steinke <lintec@engsoc.queensu.ca> writes:
> The problem with my code seems to be that the "given_field" variable isn't
> being interpolated in the assignment statement.

plpgsql is not a string-substitution language; you cannot expect the
value of a variable to be used as a table or field name in a query.
This is true because plpgsql precompiles queries into query plans
and saves the plans for repeated execution.  That's a win for speed
but costs flexibility.

You *can* get that sort of result in pltcl or plperl, which don't do
any fancy caching.  You just form the query as a string value using the
usual expression evaluation rules of those languages, and that string
gets submitted to the SQL parser and query engine.  Less speed, more
flexibility.

I believe 7.1's plpgsql will have an EXECUTE <string> command that lets
you get the second effect in plpgsql too.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: backup and store oids
Следующее
От: Doug Semig
Дата:
Сообщение: Re: Database cluster?