If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > problems with dynamic query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-04, 02:28
C_BHANDARY C_BHANDARY is offline
Registered User
 
Join Date: Apr 2004
Posts: 49
Question problems with dynamic query

Hi,
I am writing an function which takes an ip integer matches it with table columns functions and gives out the records;

create table customer(customerid int,resellerid int);

insert into customer values (156,1);
insert into customer values (157,1);
insert into customer values (158,1);
insert into customer values (159,1);


create or replace function f_c(text) returns record as '
declare ip alias for $1;rec record;
begin
for rec in execute ''select customerid,resellerid from customer where customerid in ('' || ip || '')''
loop
return rec;
end loop;
end;' language plpgsql;


This works fine when i execute the command :-

select * from f_c('157') as (c int,r int);

but when i execute the below function to get a set of records then:-

create or replace function f_c(text) returns setof record as '
declare ip alias for $1;rec record;
begin
for rec in execute ''select customerid,resellerid from customer where customerid in ('' || ip || '')''
loop
return rec;
end loop;
end;' language plpgsql;

select * from f_c('157,156') as (c int,r int);

Then it doesn't return any value, even though it doesn't give any errors.

Thanks for any help in advance.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On