Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 805C7633B9B for ; Thu, 25 Mar 2010 04:54:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 48236-06 for ; Thu, 25 Mar 2010 07:54:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id E5C7B632269 for ; Thu, 25 Mar 2010 04:54:07 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id 7B856301E6F3 for ; Thu, 25 Mar 2010 08:54:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wbTxVWWUyf6y for ; Thu, 25 Mar 2010 08:54:06 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id 599E3301E6E7 for ; Thu, 25 Mar 2010 08:54:06 +0100 (CET) Received: from delos.apartia.fr (delos.apartia.fr [10.0.3.107]) by zenon.apartia.fr (Postfix) with ESMTP id 019F45B93F308 for ; Thu, 25 Mar 2010 08:54:05 +0100 (CET) Received: by delos.apartia.fr (Postfix, from userid 1000) id D77BB2012C99D; Thu, 25 Mar 2010 08:54:05 +0100 (CET) Date: Thu, 25 Mar 2010 08:54:05 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: Does IMMUTABLE property propagate? Message-ID: <20100325075405.GA17176@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <162867791003250027q3cfc5ba9g59d56768aa4c4e5e@mail.gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/181 X-Sequence-Number: 33888 On Thu, Mar 25, 2010 at 08:27:27AM +0100, Pavel Stehule wrote: > 2010/3/25 Louis-David Mitterrand : > > On Sat, Mar 06, 2010 at 04:31:55PM -0500, Tom Lane wrote: > >> Petru Ghita 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?