Thread: dynamic sql in PL-Pgsql ?
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
On 26/09/2008 21:19, Gauthier, Dave wrote: > 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? http://www.postgresql.org/docs/8.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN ------------------------------------------------------------------ Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland rod@iol.ie Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals ------------------------------------------------------------------