dynamic sql in PL-Pgsql ? - Mailing list pgsql-general

From Gauthier, Dave
Subject dynamic sql in PL-Pgsql ?
Date
Msg-id 0836165E8EE50F40A3DD8F0D87137267012158BE@azsmsx421.amr.corp.intel.com
Whole thread Raw
Responses Re: dynamic sql in PL-Pgsql ?
List pgsql-general

Hi:

 

I want to do something like this.....

 

 

create or replace function foo(varchar, varchar) returns integer as $$

declare

  user_attrib   alias for $1;

  attrib_val    alias for $2;

  rec record;

 

begin

 

  for rec in

    select name from people_table where user_attrib = attrib_value

  loop

     insert into my_temp_table (attrib, value, name) values (user_attrib, attrib_value, rec.name);

  end loop;

 

end;

$$ language plpgsql;

 

As you can see, the select statement needs to be dynamic in that the column name is stored in a variable.

 

Can this be done?

 

Thanks

-dave

 

 

 

 

 

 

 

pgsql-general by date:

Previous
From: Decibel!
Date:
Subject: Is there any way to reliably influence WHERE predicate evaluation ordering?
Next
From: Raymond O'Donnell
Date:
Subject: Re: dynamic sql in PL-Pgsql ?