Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 60407632CCD for ; Thu, 25 Mar 2010 13:26:26 -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 34623-03 for ; Thu, 25 Mar 2010 16:26:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f46.google.com (mail-ww0-f46.google.com [74.125.82.46]) by mail.postgresql.org (Postfix) with ESMTP id B9EA96332CE for ; Thu, 25 Mar 2010 13:26:14 -0300 (ADT) Received: by wwe15 with SMTP id 15so6001386wwe.19 for ; Thu, 25 Mar 2010 09:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=BN+GFXrEoCBgS6Qtcykle32c4SGu9qSrN6sjmvoikyE=; b=l5SKJcuflmBGg22DIArdWDN3uDXWdoXl3oJ8BwJQEqcurTgemK2gZql9UV9KI7UpNE 212Qd1pSrDLWrKsj1cpZHuaNgMIwFvwoH5vpXS5oVdMwJ9w0FkKahozupqMImNmjTDMv veQeblAfbKXEn68igdhDU++4m41Hkcemccm9Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=jJeCCBplMTQerqUq/Qyk8cK87eDB0mVoe8gqNw/4Op7/b31K4R8vMgLbxrn68/C+PD 9y207lTstyuzosgLtJqvMgCVx5GlnEzFsW3+LWdpVZLiigKj+BYoVSTlYGkCltpHmb8W mMdAPBtEgaH8lrspiAEQtbIBckqge3mRUqrUo= MIME-Version: 1.0 Received: by 10.216.88.143 with SMTP id a15mr2502434wef.6.1269534373553; Thu, 25 Mar 2010 09:26:13 -0700 (PDT) In-Reply-To: <20100325075405.GA17176@apartia.fr> 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> <20100325075405.GA17176@apartia.fr> Date: Thu, 25 Mar 2010 17:26:13 +0100 Message-ID: <162867791003250926v4230f599u13f82d3a56ffd877@mail.gmail.com> Subject: Re: Does IMMUTABLE property propagate? From: Pavel Stehule To: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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/189 X-Sequence-Number: 33896 2010/3/25 Louis-David Mitterrand : > 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: >> > >> > >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0CREATE OR REPLACE FUNCTION shorten_cruise_t= ype(intext text) RETURNS text >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0AS $$ >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0declare >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0outtext text; >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0begin >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0outtext =3D tri= m(regexp_replace(intext, E'\\s*Short( Break)?', '', 'i')); >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return outtext; >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0end; >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0$$ >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LANGUAGE plpgsq= l; >> > >> >> 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? > sure Pavel > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >