Stable function Repeatedly Called

From: "CN LIOU" <cnliou(at)graffiti(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Stable function Repeatedly Called
Date: 2003-01-10 07:57:19
Message-ID: 20030110075719.3397.qmail@graffiti.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

drop table tt1;
create table tt1 (c1 text,c2 text);
drop table tt2;
create table tt2 (c1 text,c2 text);
insert into tt1 values('a','aa');
insert into tt1 values('b','bb');
insert into tt1 values('c','cc');
insert into tt2 values('x','a');
insert into tt2 values('y','b');

CREATE OR REPLACE FUNCTION f1(TEXT) RETURNS TEXT AS'
DECLARE
MyNumber TEXT;
BEGIN
SELECT c2 INTO MyNumber FROM tt2 WHERE c1 = $1;
RAISE NOTICE ''%'',MyNumber; --for debug
RETURN MyNumber;
END' LANGUAGE 'plpgsql' STABLE;

select * from tt1 where c1=f1('x');
update tt1 set c2='ABC' WHERE c1=f1('x');

I thought function "f1" would get called only once but actually it is called 3 times. How do I force it to be called only once in the same SQL?
--
_______________________________________________
Get your free email from http://www.graffiti.net

Powered by Outblaze

Responses

Browse pgsql-general by date

  From Date Subject
Next Message CN LIOU 2003-01-10 07:58:29 Hope Rule Is Willing To Discard Result Sets
Previous Message Christoph Dalitz 2003-01-10 07:55:04 Re: Version Problems on Mac OS X.2 Jaguar