Re: using for rec inside a function: behavior very slow - Mailing list pgsql-sql

From Tom Lane
Subject Re: using for rec inside a function: behavior very slow
Date
Msg-id 24884.986260616@sss.pgh.pa.us
Whole thread Raw
In response to using for rec inside a function: behavior very slow  (Jie Liang <jliang@ipinc.com>)
List pgsql-sql
Jie Liang <jliang@ipinc.com> writes:
>      v_url:= $1||''%'';                
>      for rec in select id,url from urlinfo where url like v_url order by
> url loop

[ is slow ]

LIKE index optimization doesn't happen if the LIKE pattern is a variable
when the plan is created.

In 7.1 you can work around this problem by using plpgsql's FOR ... EXECUTE
notation, but I don't think there's any good answer in 7.0.

for rec in execute ''select id,url from urlinfo where url like ''||quote_literal(v_url)||'' order by url'' loop
        regards, tom lane


pgsql-sql by date:

Previous
From: Jie Liang
Date:
Subject: select statement inside a function: behavior bad
Next
From: Tom Lane
Date:
Subject: Re: very very slow .....