using for rec inside a function: behavior very slow

From: Jie Liang <jliang(at)ipinc(dot)com>
To: edipoelder(at)ig(dot)com(dot)br
Cc: pgsql-sql(at)postgresql(dot)org
Subject: using for rec inside a function: behavior very slow
Date: 2001-04-02 22:10:40
Message-ID: Pine.BSF.4.10.10104021504210.82239-100000@tidal.ipinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-sql


I have a function:
CREATE FUNCTION hasdup(text) RETURNS int4 AS '
declare
v_id int4;
rat1 text;
rat2 text;
v_url text;
rec record;

begin
select id into v_id from urlinfo where url = $1;
if NOT FOUND then
return -1;
end if;
select codestr(v_id) into rat1;
v_url:= $1||''%'';
for rec in select id,url from urlinfo where url like v_url order by
url loop
raise notice ''%'',rec.url;
select codestr(rec.id) into rat2;
if rec.id <> v_id and rat1 = rat2 then
update urlinfo set list = 1 where id = rec.id;
return rec.id;
end if;
end loop;
return 0;
end;
' LANGUAGE 'plpgsql';

'where url like clause' is very slow in inside the function,
but when I directly use this statement in SQL, it is very quick,
is any quick way to return match:
where field like 'something%' inside the plsql function??

Jie LIANG

St. Bernard Software

10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873

jliang(at)ipinc(dot)com
www.stbernard.com
www.ipinc.com

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Jie Liang 2001-04-03 00:04:13 select statement inside a function: behavior bad
Previous Message edipoelder 2001-04-02 20:47:54 Re: Fwd: Calling functions inside a function: behavior

Browse pgsql-sql by date

  From Date Subject
Next Message Jie Liang 2001-04-03 00:04:13 select statement inside a function: behavior bad
Previous Message edipoelder 2001-04-02 20:47:54 Re: Fwd: Calling functions inside a function: behavior