pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
To: pgsql-sql@postgresql.org
Subject: Re: Does IMMUTABLE property propagate?
Date: Thu, 25 Mar 2010 08:54:05 +0100
Message-ID: <20100325075405.GA17176@apartia.fr> (raw)
In-Reply-To: <162867791003250027q3cfc5ba9g59d56768aa4c4e5e@mail.gmail.com>
References: <4B91C184.4090906@venaver.info>
	<407d949e1003060645i408e0648te67dfd722172f76a@mail.gmail.com>
	<4B927FED.60209@venaver.info>
	<4150.1267911115@sss.pgh.pa.us>
	<20100325061616.GA4629@apartia.fr>
	<162867791003250027q3cfc5ba9g59d56768aa4c4e5e@mail.gmail.com>

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?



view thread (12+ messages)  latest in thread

Message-ID: <20100325075405.GA17176@apartia.fr>
Permalink:  ../20100325075405.GA17176@apartia.fr/
Also on:    postgresql.org/message-id/20100325075405.GA17176@apartia.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: vindex+lists-pgsql-sql@apartia.org
  Subject: Re: Does IMMUTABLE property propagate?
  In-Reply-To: <20100325075405.GA17176@apartia.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox