Re: Does IMMUTABLE property propagate?

Поиск
Список
Период
Сортировка
От Louis-David Mitterrand
Тема Re: Does IMMUTABLE property propagate?
Дата
Msg-id 20100325075405.GA17176@apartia.fr
обсуждение исходный текст
Ответ на Re: Does IMMUTABLE property propagate?  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: Does IMMUTABLE property propagate?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Does IMMUTABLE property propagate?  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-sql
On Thu, Mar 25, 2010 at 08:27:27AM +0100, Pavel Stehule wrote:
> 2010/3/25 Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>:
> > On Sat, Mar 06, 2010 at 04:31:55PM -0500, Tom Lane wrote:
> >> Petru Ghita <petrutz@venaver.info> writes:
> >> > "..immediately replaced with the function value" doesn't mean that the
> >> > results of a previously evaluated function for the same parameters are
> >> > stored and reused?
> >>
> >> No, it means what it says: the function is executed once and replaced
> >> with a constant representing the result value.
> >
> > So for example a function like:
> >
> >
> >        CREATE OR REPLACE FUNCTION shorten_cruise_type(intext text) RETURNS text
> >                AS $$
> >        declare
> >                outtext text;
> >        begin
> >                outtext = trim(regexp_replace(intext, E'\\s*Short( Break)?', '', 'i'));
> >                return outtext;
> >        end;
> >        $$
> >                LANGUAGE plpgsql;
> >
> 
> yes it should be declared as immutable. plpgsql function is black box
> for executor, so you have to use some flag. language sql is different,
> executor see inside, so there you can not do it.

Hmm, that's interesting. So for simple functions (like my example) it is
better to write them in plain sql? And in that case no 'immutable' flag
is necessary?


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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: Does IMMUTABLE property propagate?
Следующее
От: Ireneusz Pluta
Дата:
Сообщение: Week to date function