dynamic sql in PL-Pgsql ?

Поиск
Список
Период
Сортировка
От Gauthier, Dave
Тема dynamic sql in PL-Pgsql ?
Дата
Msg-id 0836165E8EE50F40A3DD8F0D87137267012158BE@azsmsx421.amr.corp.intel.com
обсуждение исходный текст
Ответы Re: dynamic sql in PL-Pgsql ?  (Raymond O'Donnell <rod@iol.ie>)
Список 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 по дате отправления:

Предыдущее
От: Decibel!
Дата:
Сообщение: Is there any way to reliably influence WHERE predicate evaluation ordering?
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: dynamic sql in PL-Pgsql ?