can i use a string in where clause such as "id in (str)"

From: "Yavuz Kavus" <yavuzkavus(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: can i use a string in where clause such as "id in (str)"
Date: 2006-06-11 21:05:07
Message-ID: 95b926fc0606111405l54ef91cfsb05b1d9b958da943@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi every body.
i have a pl/pgsql function (i want to form it to run correctly) :

CREATE OR REPLACE FUNCTION "public"."ftest" () RETURNS boolean AS
$body$
declare
f boolean;
str varchar(100);
begin
str := '1,5,10';
if exists( select 1 from tb_categories where cat_id in ( str ) )
then
return true;
else
return false;
end if;
end;
$body$
LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY INVOKER;

there is a "10" value for cat_id(int4) column which should make function
return true.

but, str is seen as a string value as whole, so it doesnt return true.

i achived this by using execute command on string.
but i dont want to use execute, because there is no prepared plan for it(i
am not sure, but it may slow down procedure).

how can i achive this, are there any solutions?

thanks for any help.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Qingqing Zhou 2006-06-12 01:47:04 Re: Insert into partition table hangs
Previous Message David Fetter 2006-06-11 18:15:40 Re: Fabian Pascal and RDBMS deficiencies in fully